Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
TkDodo merged 6 commits into TanStack:main from imadselka:docs/add-stale-true-active-example
Sep 1, 2025

Conversation

Copy link
Contributor

@imadselka imadselka commented Aug 12, 2025
edited by coderabbitai bot
Loading

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.

Summary by CodeRabbit

  • Refactor

    • Simplified React Native refresh-on-focus hook to use QueryClient and refetch active, stale queries on focus.
    • Removed refetch callback; API changed from useRefreshOnFocus(refetch) to useRefreshOnFocus().
    • First focus after mount is skipped to avoid redundant requests.
  • Documentation

    • Updated examples and wording to reflect the new parameterless API and behavior.
    • Added guidance on useQueryClient import and clarified that active, stale queries are refreshed on focus.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Aug 12, 2025
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?

Copy link
Contributor 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' })

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

imadselka reacted with thumbs up emoji

Copy link

coderabbitai bot commented Sep 1, 2025
edited
Loading

Caution

Review failed

The pull request is closed.

Walkthrough

Replaced 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

Cohort / File(s) Summary
React Native hook docs update
docs/framework/react/react-native.md
- Hook API: useRefreshOnFocus<T>(refetch: () => Promise<T>)useRefreshOnFocus()
- Uses useQueryClient and queryClient.refetchQueries({ queryKey: ['posts'], stale: true, type: 'active' }) on focus
- Dependency array changed to [queryClient]
- Docs note: initial focus skipped; subsequent focuses refetch active stale queries
- Added useQueryClient import from @tanstack/react-query

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I thump my paws and hop with cheer,
No callbacks now, the path is clear!
On focus, queries leap and spring—
The client calls, refresh they bring.
First glance we skip, then off we go,
Active, stale—refetch in flow. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b998f68 and 627f543.

📒 Files selected for processing (1)
  • docs/framework/react/react-native.md (2 hunks)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

nx-cloud bot commented Sep 1, 2025
edited
Loading

View your CI Pipeline Execution ↗ for commit 627f543

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ⛔ Cancelled 19s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2025年09月01日 10:52:44 UTC

@TkDodo TkDodo merged commit 0650eaf into TanStack:main Sep 1, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@TkDodo TkDodo TkDodo left review comments

Assignees
No one assigned
Labels
documentation Improvements or additions to documentation
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /