Skip to content

docs: clarify queryClient refetch behavior for stale queries #9560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

imadselka
Copy link

@imadselka imadselka commented Aug 12, 2025

This pull request updates the documentation for the useRefreshOnFocus custom hook in the React Native guide to clarify its behavior and improve its implementation. The hook now refetches all active stale queries on screen focus, rather than requiring a specific refetch function to be passed in.

Documentation and code improvements:

  • Updated the description and implementation of useRefreshOnFocus to indicate that it refetches all active stale queries when the screen is focused, using queryClient.refetchQueries instead of a provided refetch function. [1] [2]
  • Clarified the explanation about skipping the first focus to reflect the new implementation and behavior.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Aug 12, 2025
@TkDodo
Copy link
Collaborator

TkDodo commented Aug 12, 2025

i was more thinking to have this directly in the react native example instead of calling refetch() like we recommend now?

@imadselka
Copy link
Author

yes you are right , i changed it .
but another thing do you think we should add it in the main refetchQueries docs like this

// refetch all stale queries: 
await queryClient.refetchQueries({ stale: true })

// refetch only stale queries that are currently active (recommended for RN screen-focus)
await queryClient.refetchQueries({ stale: true, type: 'active' })

@heisenbugged
Copy link

my recommendation here is to still pass in a query key so it's refresh on focus tied to a specific query rather than a blanket refresh everything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants