useQuery keeps fetching data even tho the dependency doesnt change
useQuery keeps fetching data even tho the dependency doesnt change.
It randomly refetches the data.
4 Replies
complex-tealOP•3y ago
Oh, so it refetches data when I change my browser tab and come back, and click on website.
stormy-gold•3y ago
Window Focus Refetching | TanStack Query Docs
If a user leaves your application and returns and the query data is stale, TanStack Query automatically requests fresh data for you in the background. You can disable this globally or per-query using the refetchOnWindowFocus option:
Disabling Globally
absent-sapphire•3y ago
And also by default staleTime is 0 so data are considered stale immediately after being fetched
So I suggest to set a staleTime first. And then decide whether or not ton’ disable windows focus refetch which would only happen if data are stale
xenophobic-harlequin•3y ago
If you're using version 4 your query key should be an array by the way