Repository navigation
How refresh data only if the page is out of focus? #2530
Replies: 2 comments
|
the above config should trigger a request every 3 seconds if the page is active and if the page is in the background, so basically, every 3 seconds no matter where you are. What is not working with the config, and can you reproduce it in a codesandbox? |
|
For polling only while the tab is hidden, drive the interval from document.visibilityState. Store hidden in React state, initialize/update it from a visibilitychange listener in useEffect, and pass refetchInterval: hidden ? 3000 : false, refetchIntervalInBackground: true, refetchOnWindowFocus: false. The state change makes the observer recalculate the interval when the tab's visibility changes. Use a guard or a client effect before accessing document in an SSR app. This controls periodic polling: the initial fetch, reconnect, and invalidation have separate triggers. Background timers are also subject to browser throttling, so 3 seconds is a target interval. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have a task to refresh data only if the page is out of focus. I used the params below, but it didn't help me.
All reactions