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
bigsexy
bigsexy3y ago
trpc.useContext().queryClient.invalidateQueries({
predicate: (query) => query.queryKey.includes("user."),
});
trpc.useContext().queryClient.invalidateQueries({
predicate: (query) => query.queryKey.includes("user."),
});
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
const queryContext = trpc.useContext()
const queryContext = trpc.useContext()
first
karlosos
karlososOP3y ago
@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?
julius
julius3y ago
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
const utils = trpc.useContext()

utils.user.invalidate()
const utils = trpc.useContext()

utils.user.invalidate()
Should be a thing in beta.12 mb wasn’t merged yet just approved :/ beta.13 should be it then so prob later today
karlosos
karlososOP3y ago
Seems good! Thanks for the help
bigsexy
bigsexy3y ago
thanks for the heads up. this would tripped me up when i migrate to v10
Want results from more Discord servers?
Add your server