Refresh On Focus

Sometimes, you need to ensure data consistency between multiple browser windows; or when the user's computer is reactivated in the dormant state, the page data needs to be synchronized to the latest state. refreshOnWindowFocus may save you a lot of code.

In the demo below, we use iframe to simulate multiple tabs of the browser. When you modify the login status in any tab, and then switch to another tab, the data will be synchronized.

You can copy the link in the address bar above the demo and try this in your browser.

RefocusTimespan

If you don’t want users to frequently trigger refreshOnWindowFocus in a short time to cause frequent requests, you can modify refocusTimespan to extend the trigger interval.

const { data } = useRequest('api/user', {
  refreshOnWindowFocus: true,
  refocusTimespan: 2000, // 2s
});


 

Last Updated: 6/6/2023, 4:05:10 AM
Contributors: John