mark salsbery
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
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
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
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
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
How can I disable batching with fastify adapter?
Maybe use httpLink instead of httpBatchLink?
https://trpc.io/docs/links/httpLink
3 replies
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