This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
✨ Support use of onInitialValueChanged prop with fields having nested properties #464
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.
#446 introduced the
onInitialValueChanged
prop to<FormState />
, allowing control over the form's reset behaviour when the value of theinitialValues
prop changed.The problem
When
onInitialValueChanged
is set toreset-where-changed
, only fields whose initial values had been changed are reset. However,!==
was being used to check for changes rather than a deep equality check. This meant that for fields that had nested properties, if the field's initial value pointed to a new object but with unchanged values from the previous,<FormState />
would interpret that the field's initial value had changed, and would reset it.The suggested fix
This PR introduces a deep equality check to support having complex fields for which we cannot rely on shallow equality. It also makes the reconciliation more consistent with the deep equality check performed by default when no value is specified for
onInitialValueChanged
.Some concerns
onInitialValueChanged
?