trpc v10 Invalidating all queries from given router
Is it possible to invalidate all the queries under given router? Similarly as it is in react-query: https://tanstack.com/query/v4/docs/guides/query-invalidation
Can I use query-client in trpc in the same way?
Query Invalidation | TanStack Query Docs
Waiting for queries to become stale before they are fetched again doesn't always work, especially when you know for a fact that a query's data is out of date because of something the user has done. For that purpose, the QueryClient has an invalidateQueries method that lets you intelligently mark queries as stale and potentially refetch them too...
5 Replies
u can do something like this to invalidate every query under
user
router.
you might not be able to do it all in one line without breaking react hook rules.
might have to do something like
first@bigsexy
There is no such field in
trpc.useContext()
as queryClient
. I get only my routes there.
Something wrong with my config? I started fresh with createt3app@next
. Maybe it's because of trpc v10?We removed the queryClient from the context since it caused some confusion. You should just import it from react-query
But I think if you are on latest beta you can actually do .invalidate() on a router now, that PR was merged yesterday
So
Should be a thing in beta.12
mb wasn’t merged yet just approved :/ beta.13 should be it then so prob later today
Seems good! Thanks for the help
thanks for the heads up. this would tripped me up when i migrate to v10