mark salsbery
mark salsbery
TtRPC
Created by .nickman on 7/4/2023 in #❓-help
useMutation in useEffect dependency array causes infinite loop
sumMutation isn’t a function, it’s the return value of a call to useMutation It looks to me like the useEffect is redundant anyway…you should be able to mutate from your event handlers
3 replies
TtRPC
Created by test_1 on 6/20/2023 in #❓-help
whats the difference between context and middleware
Context is data, middleware is code. Middleware allows you to add reusable code to your procedures - code that runs before and/or after your procedure code. Your context data is typed, and available in all your procedures and their attached middleware. Your context is created on every request, so one way you could handle session cookies is to extract the cookie from the request headers in your createContext function and add the desired session data to your context. Session cookies could be set on the response headers of a login procedure, The docs show examples… https://trpc.io/docs/server/context https://trpc.io/docs/server/middlewares
2 replies
TtRPC
Created by Daniel on 6/13/2023 in #❓-help
Query data is undefined for a bit and is then populated. How to use with React State?
The hook is really designed to be used data driven…let the queries happen when input data changes, and use the returned state variables to drive the ui as they change. No need to manually refetch and no need to duplicate the returned data (state). I suppose if you must do it all manually then an onSuccess callback could be used on the query. But the callbacks are deprecated. That leaves a useEffect I guess, since technically when the query gets to the state you want it’s a side effect… Regardless, as you’ve seen you can’t just use query.data when the refetch promise resolves. At that point I’m pretty sure query is the same set of state variables returned by useQuery
5 replies
TtRPC
Created by hachoter on 4/23/2023 in #❓-help
convert the result to date objects
6 replies
TtRPC
Created by Barakonda on 3/31/2023 in #❓-help
async middleware
@Barakonda yes async works…where is the exception occurring?
4 replies
TtRPC
Created by Hussam on 3/30/2023 in #❓-help
The inferred type of this node exceeds the maximum length the compiler will serialize.
Yes that’s what i meant…or use router({…}) for namespaced endpoints. I’ve never seen the two mixed so I’m curious https://trpc.io/docs/server/merging-routers#merging-with-tmergerouters
19 replies
TtRPC
Created by Hussam on 3/30/2023 in #❓-help
The inferred type of this node exceeds the maximum length the compiler will serialize.
Just for my own sanity, why are you merging 2 un-namespaced routers with the second one an already merged set of namespaced routers?
19 replies
TtRPC
Created by Lois on 3/6/2023 in #❓-help
Data Visualisation/Charts
Hi @Lois they aren’t really related. tRPC provides a dev friendly typesafe RPC way of handling communication/data between endpoints but using data for visualization is a separate issue
2 replies
TtRPC
Created by Mugetsu on 3/6/2023 in #❓-help
Fetching different server url than defined in config
A query function can fetch any way you desire. See the Tanstack Query useQuery docs for examples. On the tRPC side, everything you need to know should be here (mostly relevant is the example of getting the query client) https://trpc.io/docs/useContext#helpers
4 replies
TtRPC
Created by Mugetsu on 3/6/2023 in #❓-help
Fetching different server url than defined in config
Yes you can use React Query
4 replies
TtRPC
Created by Barakonda on 3/4/2023 in #❓-help
input using z.or not working properly
Cool, like @Nick Lucas mentioned, if you think about how it works, with the optional, if the property isn’t there you get the “else” which is {} … the other object definition in the union isn’t looked at
12 replies
TtRPC
Created by kalempster on 3/4/2023 in #❓-help
Error types in catch block
@kalempster What is mutateAsync in your example code? I don’t see any use of tRPC there…
3 replies
TtRPC
Created by Barakonda on 3/4/2023 in #❓-help
input using z.or not working properly
@Barakonda does it work if you remove the optional() calls?
12 replies
TtRPC
Created by Barakonda on 3/2/2023 in #❓-help
How can I disable batching with fastify adapter?
Maybe use httpLink instead of httpBatchLink? https://trpc.io/docs/links/httpLink
3 replies
TtRPC
Created by JavascriptMick on 2/25/2023 in #❓-help
is context cached?
Back to the original post, you could mutate ctx.dbUser but next request will use whatever dbUser was. Subsequent createContext calls aren’t going to refresh dbUser unless it’s falsey. dbUser is already “cached” somewhere according to your code sample so you’ll need to manage it Edit: I should have stated “you could mutate the value of ctx.dbUser…”.. 😅
7 replies
TtRPC
Created by JavascriptMick on 2/25/2023 in #❓-help
is context cached?
I guess your dbUser reference exists outside of createContext so yeah you’d have to handle that however you need to. That’s a JavaScript thing, not tRPC specific
7 replies
TtRPC
Created by JavascriptMick on 2/25/2023 in #❓-help
is context cached?
I don’t see how, I’m missing something
7 replies
TtRPC
Created by JavascriptMick on 2/25/2023 in #❓-help
is context cached?
createContext is called for every request AFAIK but I thought I just read it was just once per set of batched requests…
7 replies