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
conscious-sapphireOP•6mo ago
Should I also set
defaultStaleTime to 0?flat-fuchsia•6mo ago
"run once" per what?
conscious-sapphireOP•6mo ago
just once, same as with basic tanstack query
stale time Infinity
disable refetches
and it runs once...
flat-fuchsia•6mo 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
conscious-sapphireOP•6mo ago

conscious-sapphireOP•6mo 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
flat-fuchsia•6mo ago
preloadStaleTime defaults to defaultPreloadStaleTime
ah wait
defaultStaleTime is 0 by default
conscious-sapphireOP•6mo 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?
flat-fuchsia•6mo ago
yes