fix(react-form): Make form.options reactive by adding getter#2044
fix(react-form): Make form.options reactive by adding getter#2044swushi wants to merge 1 commit intoTanStack:mainfrom
Conversation
|
Fixes an issue where form.options.defaultValues was not reactive when initializing a form with async data. The options object was captured in the useMemo closure and never updated when formApi.options changed. Adding a getter for options (similar to the existing state getter) ensures that the latest options are always returned, fixing reactivity issues when comparing current values to defaultValues.
9fc39cc to
29a65ed
Compare
|
View your CI Pipeline Execution ↗ for commit 29a65ed
☁️ Nx Cloud last updated this comment at |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2044 +/- ##
===========================================
- Coverage 90.35% 57.08% -33.28%
===========================================
Files 38 18 -20
Lines 1752 240 -1512
Branches 444 36 -408
===========================================
- Hits 1583 137 -1446
+ Misses 149 91 -58
+ Partials 20 12 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Fixes an issue where
form.options.defaultValueswas not reactive when initializing a form with async data.Problem
When using
useForm()with async data:Root Cause
The
optionsobject was captured in theuseMemoclosure and never updated whenformApi.optionschanged, even thoughformApi.update()was called in the effect lifecycle.Solution
Added a getter for
options(similar to the existingstategetter) to ensure the latest options are always returned:This follows the same pattern as the
stategetter, as mentioned in the existing comment: "We must add allgetters fromcore'sFormApihere, as otherwise the spread operator won't catch those"Related Discussion
https://canary.discord.com/channels/719702312431386674/1471891391348215972