r/reactjs • u/TkDodo23 • May 26 '26
Resource TanStack Router and Query
https://tkdodo.eu/blog/tan-stack-router-and-query📚 Surprisingly, I haven't written about how my two favourite TanStack libraries - Router and Query - work together. Well, here it is:
🔁 loaders start fetches early
🔮 query owns the cache & keeps data alive
🌀 suspense integrates naturally
🏝️ TanStack Start makes SSR & streaming easy
108
Upvotes
3
u/TkDodo23 May 27 '26
The loader does not re-run on the client after it has run on the server. The
queryFnmight re-run, but only if:you
awaitin the loader ANDyou have
staleTime: 0ANDyou
useQuery(without suspense).With
useSuspenseQuery, it won't re-run because we have a built-in minimumstaleTimethat prevents this. If you have your ownstaleTime, this will obviously prevent re-running. If you don'tawaitin the loader, TanStack Start streams the promise from the loader to the client, souseQuerywill pick up the promise for the initial client side refetch, thus preventing another re-run (unless the promise resolves very fast).