-
Notifications
You must be signed in to change notification settings - Fork 220
Add option to use a custom comparator for dirty state checking #1296
Conversation
4d2af14
to
68ff637
Compare
cd996c9
to
da0c883
Compare
027044a
to
6a0e114
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One implementation question, otherwise looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few suggestions for minor tweaks from me, changes overall make sense.
}; | ||
} | ||
} | ||
export function reduceField<Value>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this and the shallowFieldReducer
feel like they may belong somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like that to me too, but I just tried moving it out of that file and couldn't find a place that felt right because the call to makeFieldReducer
would have to call back here anyway. 😕
0914ebb
to
55a3e9c
Compare
55a3e9c
to
e26f69f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
This change adds an option to the
useField
hook inreact-form
to use a custom comparator for checking whether a field is dirty. This allows you to, for example, apply a deep equals function for deep equality checking if you field requires it:This is required to resolve a bug we have an in upcoming Web feature (Slack me for more details) where we are storing a list of objects in a field, and currently we remain in the dirty state if the user manually resets the form to its default state. With this feature, we correctly detect that the form is again in its default state, and report that it's now clean.
Note: I recommend turning on "Hide whitespace changes" when reviewing this feature to make the diff readable.
Type of change
react-form
Minor: New feature (non-breaking change which adds functionality)Checklist