shadcn-ahooks
useRequest

RefreshOnWindowFocus

The API useRequest

RefreshOnWindowFocus

By setting options.refreshOnWindowFocus, the request will be refreshed when the browser is refocus and revisible.

const { data } = useRequest(getUsername, {
  refreshOnWindowFocus: true,
});

You can click outside the browser, and then click the current page to experience the effect (or hide the current page and redisplay). If the interval from the previous request is greater than 5000ms, it will be requested again.

API

Options

PropertyDescriptionTypeDefault
refreshOnWindowFocusWhether to re-initiate the request when the screen refocus or revisible.booleanfalse
focusTimespanRe-request interval, in millisecondsnumber5000

Remark

  • options.refreshOnWindowFocus, options.focusTimespan support dynamic changes.
  • Listen for browser events visibilitychange and focus.

On this page