automatic refetching only on key change (no refetch of stale data) #8306
-
Use case:
The idea:
Unfortunately I expected that isStale would still change even if the query is disabled but it does not. Refetching the disabled query works tho. Is there a way how to make it work?
Code snippets with my configuration: queryOptions({
queryKey: ['foo', page],
queryFn: async () => {
...
},
retry: false,
placeholderData: keepPreviousData,
staleTime: Infinity,
enabled: false,
}); queryClient.invalidateQueries({
queryKey: ['foo'],
type: 'all',
}); EDIT: Actually, changing page won't work as well. I've got confused while trying different options. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Funny because I’ve just implicitly addressed it in this PR: I used to make a fix that said that disabled queries shouldn’t be shown as |
Beta Was this translation helpful? Give feedback.
-
@TkDodo Wow, that's cool. I believe this would be really helpful in my scenario. Thanks However I will still be unable to acquire the behaviour "Refetch on key change, do not refetch when it becomes stale" am I right? |
Beta Was this translation helpful? Give feedback.
staleness defines when a smart refetch should happen, so no. But you can turn off all the refetchOn... triggers and use StaleTime to just let the user know that data isn't fresh with the button