gnosis / conditional-tokens-explorer

9 stars 10 forks source link

Possible workaround react-hook-form v5 limitation #845

Open hpmaxi opened 3 years ago

hpmaxi commented 3 years ago

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 form dirty, a little hack to solve this is to check if the callback onClick was called with category 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 in setValue).

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, the useMemo doesn't run for other fields. I thought it was related to the dirtyFields set not having different identities in the shallowEqual comparison of the hook, so once the isDirtyOmenCondition (that makes the hook run) is true, the useMemo stops running.

A possible option is to use reset to only reset dirty in the first case but I didn't try that yet.

ghost commented 3 years ago

Travis automatic deployment: https://pr845--conditionaltokensexplorer.review.gnosisdev.com