Refresh On Focus
Sometimes, you need to ensure the consistency of data between multiple browser windows, or when the user's computer is reactivated from a sleep state, the page's data needs to be synchronized to the latest state. refreshOnWindowFocus
can save you a lot of logical code.
In the following example, we use iframe to simulate multiple tabs in a browser. When you modify the login status in any tab and switch to another tab, the data will be synchronized.
You can also copy the link from the address bar above the example and try this feature in your own browser.
RefocusTimespan
If you don't want the user to trigger refreshOnWindowFocus
frequently in a short period of time, causing frequent requests, you can modify the value of refocusTimespan
to extend the interval between triggers.
const { data } = useRequest(getUser, {
refreshOnWindowFocus: true,
refocusTimespan: 2 * 1000, // 2s
});