Reset({...}) does not discard default values on form inputs. #11236
Unanswered
bloodrizer
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In my use case I need to switch between unrelated forms without re-mounting the root form component.
https://codesandbox.io/p/sandbox/react-hook-form-reset-demo-forked-ffyjvl
In the following example we seed the form with the default value {"input-1": "foobar"} for the component "input-1".
Let's say we want to reset the form by removing this default value (in my case i'm omitting "input-1"'s default value entirely).
You can see that the value is retained, although I would expect it to be passed as undefined to the input-1 component.
I can see that defaultValues are actually reset correctly inside of the control, but after control is passed to the <Controller
control={control} wrapper, it's values are being merged with old defaults, and the resulting default values are a union if both old and new (i.e. {"input-1": "...", "input-2": "..."}).
The only reliable way to reset this form in my case is to unmount it completely.
Beta Was this translation helpful? Give feedback.
All reactions