tanstack query as a cache
Hi, I am using tanstack query instead of default router cache. Example from docs is using:
What is the difference between
defaultStaleTime
vs defaultPreloadStaleTime
?
That's my loader: which option is responsible for making it run only once -> The one in the querOptions or any of those 2 above?
9 Replies
ratty-blushOP•3mo ago
Should I also set
defaultStaleTime
to 0?correct-apricot•3mo ago
"run once" per what?
ratty-blushOP•3mo ago
just once, same as with basic tanstack query
stale time Infinity
disable refetches
and it runs once...
correct-apricot•3mo ago
ah yes then the in the queryclient is responsible for that
the others disable caching in router
as this is handlded by query then
ratty-blushOP•3mo ago

ratty-blushOP•3mo ago
This kitchensink doesn't disable the defaultStaleTime
only preload
why?
https://tanstack.com/router/latest/docs/framework/react/examples/kitchen-sink-react-query-file-based
So my understanding is:
Settings both to 0 will make loader run on every attempt to prefetch / load but since we use tanstack query then this data would come from cache
correct-apricot•3mo ago
preloadStaleTime defaults to defaultPreloadStaleTime
ah wait
defaultStaleTime is 0 by default
ratty-blushOP•3mo ago
okey
thanks
I guess all clear now
@Manuel Schiller so when I am using queryClient as cache then I shouldn't use hook useLoaderData and just use query client for getting the data that's fetched in loader?
correct-apricot•3mo ago
yes