fix(react-form): Make form.options reactive by adding getter#2044
Draft
swushi wants to merge 1 commit intoTanStack:mainfrom
Draft
fix(react-form): Make form.options reactive by adding getter#2044swushi wants to merge 1 commit intoTanStack:mainfrom
swushi 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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