Possible workaround react-hook-form v5 limitation #845
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.
Closes #744
In prepare omen condition the categories are dynamic, and the first category is set as the default in the dropdown controller. This changes the
dirtyFields
and makes the formdirty
, a little hack to solve this is to check if the callbackonClick
was called withcategory
not initialized and avoid making that field dirty, but this is only possible with react-hook v6, in v5 the only possible option is related to validate the form after the change (third parameter insetValue
).So I've to use a bigger hack, track the behaviour explained above with a state, and checking if the only dirtyField is
category
, but for some reason, theuseMemo
doesn't run for other fields. I thought it was related to thedirtyFields
set not having different identities in the shallowEqual comparison of the hook, so once theisDirtyOmenCondition
(that makes the hook run) istrue
, theuseMemo
stops running.A possible option is to use
reset
to only reset dirty in the first case but I didn't try that yet.