Are query keys supported in tRPC?
I'm getting an error when trying to use one on the query as per the react-query guide (https://tanstack.com/query/v4/docs/react/guides/query-keys).
The trpc docs 404 which is odd https://trpc.io/docs/query-invalidation
14 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
you probably want to pass undefined as the first parameter to useQuery
the 2nd parameter is for react-query options
Thanks I was being stupid there. Even with undefined my query doesn't re-fetch when my mutation
onSuccess
handler gets called (which I have confirmed).
My query look as such on backend
With the query in the front-end looking like this (they are in 2 separate react components, in same file)
And mutation -
Anyone have any ideas, I must be missing some thing hereusing trpc with react query
the wrapper will define the keys and such
you can use the react query devtools to check them if you want
if you want to directly invalidate something
Thanks so much @Neto I managed to get things working! this would have been really hard to figure out on my own, is there docs anywhere I missed?
It would be cool if I could use the
queryKey
as it makes things a little more declarative,
when checking the dev-tools (in screen shot) I can see trpc defined the queryKey for me, I thought I might be able to do the following -
on docs
useContext | tRPC
useContext is a hook that gives you access to helpers that let you manage the cached data of the queries you execute via @trpc/react-query. These helpers are actually thin wrappers around @tanstack/react-query's queryClient methods. If you want more in-depth information about options and usage patterns for useContext helpers than what we provide...
with trpc you shouldnt care about the query keys
as the wrapper is taking care of it
on v9 was something to worry about, not on v10
Ok yeah, I see now.
I guess
auth.invalidate
or say auth.getAllWidgets.invalidate
is exactly the same as the query syntax reallyI got hung up on this broken link... https://trpc.io/docs/query-invalidation
But yeah helps a lot, much appreciated 🙇♂️