Repository navigation
docs(react): document field state reactivity - #2445
Conversation
Explain that field state read inside `form.Field` and in field components using `useFieldContext` is kept up to date, note the array-mode exception, and show `useSelector(field.store, ...)`. Update the pre-bound `TextField` example to handle blur and show the field's errors. Closes TanStack#1207
|
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Field reactivity and usage examples docs/framework/react/guides/reactivity.md, docs/framework/react/guides/form-composition.md |
The Reactivity guide describes field state subscriptions, including the array-field exception and useSelector. The composition example marks the field touched on blur and displays nonempty errors with role="alert". |
Priority:
Estimated code review effort: 1 (Trivial) | ~5 minutes
Change: Other
Possibly related PRs
- TanStack/form#2444: Updates array-field subscriptions so an array field rerenders when its own metadata errors change, matching the documented array-field behavior.
Suggested reviewers: lecarbonator
Merge Risk: 
Minimal · up to ebdd2
-
The documentation changes are mergeable with no identified correctness or operational risk.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title "docs(react): document field state reactivity" matches the main change: new field-state reactivity guidance in the React reactivity and form-composition docs. It is concise, follows a conventional-commit style, and names the affected framework. It does not mention the array-mode exception or the TextField example update, which is acceptable because the title need not cover every detail.
Full details: Description check
-
Explanation
The description follows the template. It has a Changes section that explains the motivation (issue
#1207), the finding that field state stays current in form.Field and useFieldContext components, the files changed, and how the author verified the work. All three checklist items are checked. The release impact item marks the change as docs-only, which matches the diff. The description does not include a changeset, which is correct for a docs-only change.
Full details: Out of Scope Changes check
-
Explanation
The reviewed changes are limited to
reactivity.mdandform-composition.md. The new field-state guidance,useSelectorexample, blur handling, and error display all support issue [#1207]. No unrelated change is identified.
Full details: Docstring Coverage
-
Explanation
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (2 skipped: 2 unsupported.)
-
Full details: Linked Issues check
-
Explanation
Issue [
#1207] requires documentation for field metadata reactivity, the stale-state cause, value reactivity, and related examples. The new docs showuseSelector(field.store, ...)formeta.errorsand state thatform.Fieldsubscribes to its field. However, they do not explain why metadata becomes stale without a subscription. They also do not clearly state whether directfield.state.valuereads inuseFieldContextcomponents remain current; the guide instead gives a selector for metadata while the example readsfield.state.valuedirectly. This leaves the requested value comparison unresolved.Resolution
Add a direct explanation of the subscription boundary and stale metadata behavior. State the verified behavior for
field.state.valueandfield.state.metain bothform.Fieldrender functions anduseFieldContextcomponents. Align theTextFieldexample and the reactivity guide with that explanation.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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 @coderabbitai help to get the list of available commands.
LeCarbonator
left a comment
There was a problem hiding this comment.
Appreciate the docs addition! Some minor notes regarding useSelector, but the rest looks good!
|
View your CI Pipeline Execution ↗ for commit ebdd2bc
☁️ Nx Cloud last updated this comment at |
Co-authored-by: LeCarbonator <18158911+LeCarbonator@users.noreply.github.com>
🎯 Changes
Closes #1207.
The issue asks the docs to explain using
useStoreforfield.state.metain extracted field components, why meta goes stale without it, and to double check whetherfield.state.valueneeds it too. Before writing anything I checked this on currentmain. Since #1893,useFieldreturns a new field object whenever the field's value or meta changes, andAppFieldpasses that object throughfieldContext, so a component usinguseFieldContextre-renders along with the field. That meansfield.state.valueandfield.state.metaare already up to date there, so the docs say that instead of describing meta as stale.reactivity.md: new "Field state" section. Field state read insideform.Fieldand inuseFieldContextcomponents doesn't needuseSelectororform.Subscribe. It also notes themode="array"exception, which the existing "should not rerender array field when child field value changes" test covers, and showsuseSelector(field.store, ...).form-composition.md: the pre-boundTextFieldexample now wiresonBlurand shows the field's errors fromfield.state.meta, and links to the new section.How I checked it: I wrote a throwaway vitest file (not included here) with a
createFormHookfield component that reads meta directly, aReact.memocopy of it, and theuseSelector(field.store, ...)snippet. It covers fieldonChange/onBlurvalidators, a form-level validator, and an async validator'sisValidating. Every case passed both normally and withbabel-plugin-react-compilerenabled. As a control, I switcheduseFieldback to returning the stableFieldApi(the pre-#1893 behavior), and the memoized component went stale, which is what the issue originally described. I also type-checked the snippets with stricttscagainst the built@tanstack/react-form, andpnpm test:prpasses.Happy to take suggested changes, for example if you'd rather field components use
useSelector(field.store, ...)the way the large-form and multi-step-wizard examples do.✅ Checklist
pnpm test:pr, or these tests do not apply to this pull request.🚀 Release Impact
Summary by CodeRabbit