-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
docs: clarify queryClient refetch behavior for stale queries #9560
Conversation
i was more thinking to have this directly in the react native example instead of calling refetch()
like we recommend now?
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
commented
Aug 13, 2025
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
Caution Review failedThe pull request is closed. WalkthroughReplaced a hook’s user-provided refetch callback with a QueryClient-based refetch of active, stale queries on focus. The hook’s public signature was simplified to a parameterless export. Documentation and code snippet imports were updated to use useQueryClient and clarify first-focus skip behavior. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Nav as Navigation
participant Screen
participant Hook as useRefreshOnFocus
participant QC as QueryClient
participant RQ as React Query
User->>Nav: Navigate to Screen
Nav->>Screen: focus event (initial mount)
Note over Hook: First focus is skipped
Screen->>Hook: useRefreshOnFocus() mounted
loop On subsequent focuses
Nav->>Screen: focus event
Screen->>Hook: focus handler
Hook->>QC: refetchQueries({ queryKey: ['posts'], stale: true, type: 'active' })
QC->>RQ: Trigger refetch for matching active, stale queries
RQ-->>QC: Resolve refetches
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
View your CI Pipeline Execution ↗ for commit 627f543
☁️ Nx Cloud last updated this comment at |
Uh oh!
There was an error while loading. Please reload this page.
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 specificrefetch
function to be passed in.Documentation and code improvements:
useRefreshOnFocus
to indicate that it refetches all active stale queries when the screen is focused, usingqueryClient.refetchQueries
instead of a providedrefetch
function. [1] [2]Summary by CodeRabbit
Refactor
Documentation