Skip to main content

refetchAfterFocus

Description: Reexecute the action on window focus.

Default Value: true.

  • How To: Set refetchAfterFocus: true for data that should be fresh when the user returns to the application, such as user profiles, notifications, or shopping cart contents. This ensures the user always sees up-to-date information.
    // Correct: User profile data is refreshed when the window regains focus
    useFetch(
    'current-user',
    fetchCurrentUser,
    { refetchAfterFocus: true }
    );
  • Best Practice: Avoid refetchAfterFocus: true for data that doesn't need to be immediately fresh on focus, to prevent unnecessary network requests and potential server load.