-
Maybe I'm just misreading the documentation, but seems like const { data, error, isFetching, refetch } = useQuery(
[123],
() => api.getUserLabels(),
{ refetchOnMount: false },
); Having the above with some stale data under the key, and no observers, and then calling queryClient.invalidateQueries([123]); should not immediately reload the data, but since the request for invalidation was filed, I expect the data to be reloaded once I open the view that uses that said query key. That just seems rational. The only workaround for this that I see is to call this instead: queryClient.removeQueries([123]); But this is suboptimal since it completely wipes out the previous results, so that data will be reloaded with bulky loader instead of just unnoticable "background" one. So the question is, how to force a query to reload at the next activation without wiping out the current cache? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
That is exactly what refetchOnMount is for :). It refetches queries in the background when this observer mounts IF the query is stale. By invalidating it, it is set to stale, so it will be refetched. The question is more: why did you turn off that flag in the first place? I'm guessing it's because you got too many background refetches, to which the probably better solution would be to set a higher staleTime. |
Beta Was this translation helpful? Give feedback.
That is exactly what refetchOnMount is for :). It refetches queries in the background when this observer mounts IF the query is stale. By invalidating it, it is set to stale, so it will be refetched.
The question is more: why did you turn off that flag in the first place? I'm guessing it's because you got too many background refetches, to which the probably better solution would be to set a higher staleTime.