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
provincial-silverOP•11mo ago
I have made a small playground, I don't want to refetch when switching view: https://codesandbox.io/p/devbox/affectionate-hermann-6823nm
multiple-amethyst•11mo ago
and when I switch back to 'list1' before the 5seconds of stale time, the function is neither refetching nor taking the cached datawhat do you mean? it does take the cached data in your example
provincial-silverOP•11mo 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
multiple-amethyst•11mo ago
I'm confused.That's what staleTime does
provincial-silverOP•11mo 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
multiple-amethyst•11mo ago
so when I go back to list 1 it refetch the query even if the stale time is not reachedthat shouldn't happen unless you set
refetchOnMount: 'always'