`watch` is not returning correct values with `defaultValue` argument provided
See original GitHub issueDescribe the bug
I have a checkbox-type component in my multi-step form, which uses reset(values)
to restore the form state from higher-order state.
Inside a checkbox component I use watch('name', false)
to trigger some effects when checkbox is changed.
If I reset the form with values from state, where my value is true
, watch
still returns false
.
If I remove default value, then the value returned updates correctly, but this causes issues in my effects, so I still need this default value to be set.
I upgraded to v6.3.0, but it didn’t change anything
To Reproduce Steps to reproduce the behavior:
- Open the sandbox below
- Checkbox is checked by default. Notice that
watch
with default value returns false - When you check/uncheck the checkbox, both values get synchronized
- If you then press the
Reset
button, you will see, thatwatch
with default value returns wrong value again.
Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-useform-template-gzmmu
Expected behavior
watch
return values should be in sync with and without the defaultValue
, when the value is set in the form.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
I have same error for defaultValues not returned by watch() on first render
Please Has anyone been able to solve this. I see this in the docs for setting a default value with watch, but when I try to do this, the default value gets ovewritten with undefined