T
TanStack•14mo ago
fair-rose

How can I access to an invalidated query

Hey guys, I have 2 separated list, for instance I have a list with key ['list1'] and the other with ['list2'], both are using a stale time of 5seconds. When I navigate from the first to the second list, the query ['list1'] has no more observers and become inactive, and when I switch back to 'list1' before the 5seconds of stale time, the function is neither refetching nor taking the cached data (before it has been inactivated). - How can I not invalidate the query while navigating to the second? - is it the intended behavior or am I doing something wrong? - What should I use in my case?
6 Replies
fair-rose
fair-roseOP•14mo ago
I have made a small playground, I don't want to refetch when switching view: https://codesandbox.io/p/devbox/affectionate-hermann-6823nm
statutory-emerald
statutory-emerald•14mo ago
and when I switch back to 'list1' before the 5seconds of stale time, the function is neither refetching nor taking the cached data
what do you mean? it does take the cached data in your example
fair-rose
fair-roseOP•14mo ago
Yes sorry, it is refecting but I just want to take the cache/stale data if the stale time has not been reach before 5 seconds I don't want to refecth even if there was no listeners to the query When I switch back to list 1 I don't want to refetch if the list 1 data is not stale
statutory-emerald
statutory-emerald•14mo ago
I'm confused.That's what staleTime does
fair-rose
fair-roseOP•14mo ago
Sorry @TkDodo 🔮 I did not see your answer. yes but in my case, the list 1 query is not rendered at all while the list 2 is rendered and the query becomes inactive, so when I go back to list 1 it refetch the query even if the stale time is not reached
statutory-emerald
statutory-emerald•14mo ago
so when I go back to list 1 it refetch the query even if the stale time is not reached
that shouldn't happen unless you set refetchOnMount: 'always'

Did you find this page helpful?