T
TanStack•6mo ago
sensitive-blue

query composition/dependencies

is there any way to declare that a query depends on other queries? I am attempting to compose queries, where I have some low level ones, then a higher level one that combines them (conditionally based on some other vars) I want to make sure that when I invalidate the cache for an inner query, that the outer query also invalidates
4 Replies
exotic-emerald
exotic-emerald•3w ago
I also miss this feature. The advice you'd probably get is putting the outer query results in the inner query key
absent-sapphire
absent-sapphire•3w ago
I looked high and low for this and my finding was: not really. I switched to tanstack DB for this reason and (mostly) love it. but it is a big change. but in my tanstack query implementation I would have special composite hooks that take the results of two useQueries and do a big ol' useMemo to derive the composite state I want, and return that 🤷
exotic-emerald
exotic-emerald•3w ago
The problem with tanstack db is that you can’t really parametrize collections
deep-jade
deep-jade•3w ago
I want to make sure that when I invalidate the cache for an inner query, that the outer query also invalidates
That's what the queryKey does with fuzzy/partial matching: https://tanstack.com/query/latest/docs/framework/react/guides/query-invalidation#query-matching-with-invalidatequeries
Query Invalidation | TanStack Query React 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. Fo...

Did you find this page helpful?