docs(react): add holistic useQuery and useMutation lifecycle example#10988
docs(react): add holistic useQuery and useMutation lifecycle example#10988OluwaseunOlajide wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThe React mutations guide example now fetches todos with ChangesReact mutations guide example
🎯 1 (Trivial) | ⏱️ ~4 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/framework/react/guides/mutations.md`:
- Around line 20-23: The todo query in the useQuery example currently only
handles loading and data, so a rejected /todos request is indistinguishable from
an empty list. Update the mutations guide examples that use useQuery and render
the todos list to include an isError branch alongside isLoading, so failures are
shown explicitly instead of falling through to an empty <ul>; use the existing
todos query setup to locate the affected snippets.
- Around line 28-30: The onSuccess handler in the mutation example is not
returning the async invalidateQueries call, so the mutation can settle before
the refetch finishes. Update the onSuccess callback in the mutation example to
return the queryClient.invalidateQueries call for the ['todos'] query key, so
the mutation stays pending until the refreshed list has been fetched.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c74e7458-56a9-4bc8-83d4-790dbbf100be
📒 Files selected for processing (1)
docs/framework/react/guides/mutations.md
🎯 Changes
The primary
useMutationexample in the React mutations guide introduces the hook in isolation without demonstrating how to synchronize the state withuseQuery.This creates friction for developers learning the library, as they immediately need to know how to refresh a list after a mutation. I replaced the isolated
axios.postsnippet with a holisticTodoAppexample that demonstrates the complete, real-world lifecycle: fetching data withuseQuery, mutating it, and automatically triggering a refetch viaqueryClient.invalidateQueries.✅ Checklist
pnpm run test:pr. (N/A - Docs only change)🚀 Release Impact
Summary by CodeRabbit