How to access queryClient to invalidate cache?
In my Next app, I am initializing
queryClient
from _app.tsx
. I have some instances where I want to invalidate cache (for example when I mutate data). From the docs (v5) it seems that the only way to do this is through queryClient
.
What do you think of something like this, is it okay? It bugs me that I am importing something from _app.tsx
, at the same time I am not sure how to do otherwise.
Thank you!4 Replies
equal-aquaOP•2y ago
I just saw this, it seems to do exactly what I need!
https://tanstack.com/query/latest/docs/framework/react/reference/useQueryClient
useQueryClient | TanStack Query Docs
The useQueryClient hook returns the current QueryClient instance.
`tsx
equal-aquaOP•2y ago
I am still kind of skeptical though xD
broad-brown•2y ago
React Query FAQs
Answering the most frequently asked React Query questions
equal-aquaOP•2y ago
thank you Dominik, again haha