You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a quite complex form with a lot of dynamic form data, which depends on each other.
So e.g. if the value of fieldA changes (which is controlled by a custom component), I have to re-calculate the value of an field array fieldB since they are depended on the selection of fieldA.
Right now, I do two setValue calls in the onChange callback of my custom component of fieldA, one for updating the form value of fieldA and one for updating the re-distribution of fieldB. Unfortunately, this causes stale validation issues. So I oftentimes end up in a state, where e.g. there are errors in formState, but isValid=true or the other way round, which seems to happen due to the two setValue calls. If I wrap the second setValue call within a setTimeout(() => setValue(...), 1) everything works fine.
Btw. calling trigger() after the two setValue calls doesn't fit the issue.
I found this issue from January this year which requests a feature to support setting multiple form values at once, which was closed as "completed", but I can't find any reference in either the docs or TypeScript types that this is supported right now by the library.
So what's the recommended way to update multiple values at once?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a quite complex form with a lot of dynamic form data, which depends on each other.
So e.g. if the value of fieldA changes (which is controlled by a custom component), I have to re-calculate the value of an field array fieldB since they are depended on the selection of fieldA.
Right now, I do two
setValue
calls in theonChange
callback of my custom component of fieldA, one for updating the form value of fieldA and one for updating the re-distribution of fieldB. Unfortunately, this causes stale validation issues. So I oftentimes end up in a state, where e.g. there are errors informState
, butisValid=true
or the other way round, which seems to happen due to the twosetValue
calls. If I wrap the secondsetValue
call within asetTimeout(() => setValue(...), 1)
everything works fine.Btw. calling
trigger()
after the twosetValue
calls doesn't fit the issue.I found this issue from January this year which requests a feature to support setting multiple form values at once, which was closed as "completed", but I can't find any reference in either the docs or TypeScript types that this is supported right now by the library.
So what's the recommended way to update multiple values at once?
Beta Was this translation helpful? Give feedback.
All reactions