Reputation: 4006
After having this question answered: React Query - query is not using cache?
I had another question - what if i want to refetch the data on window focus, but not otherwise?
If i change the staleTime
to Infinity
like suggested in the question above, React Query would never refetch on window focus.
Isn't it possible to never refetch, unless there's a window focus?
Upvotes: 7
Views: 21027
Reputation: 28998
staleTime: Infinity,
refetchOnWindowFocus: 'always'
refetchOnWindowFocus
defaults to true
, which will only refetch stale queries. Set it to always
to, well, always refetch.
It's in the api reference for useQuery.
Upvotes: 22