combining react query and defer
I have a page that displays
articles
and tags
however I don't want to wait for the tags
to load before displaying the articles.
Is this the correct way to combine react query
, ensureQueryData
and defer
to achieve this result?
The full sandbox is here:
https://stackblitz.com/edit/tanstack-router-ezbw75?file=src%2Froutes%2Findex.tsx
It appears to work however I noticed that react-query
doesn't appear to track the tags
query and it is marked as inactive
Michael Wolfenden
StackBlitz
Router Basic React Query File Based Example (forked) - StackBlitz
Run official live example code for Router Basic React Query File Based, created by Tanstack on StackBlitz
3 Replies
constant-blue•12mo ago
you don't need to use
defer
use call ensureQueryData
and then another useSuspenseQuery
in the componentmultiple-amethystOP•12mo ago
@Manuel Schiller doing that will show
Loading....
(block the page) until both the articles
and tags
are loadedflat-fuchsia•12mo ago
Then just call prefetchQueryData and use TanStack Query normally using
useQuery
.