defaultValue passed to `watch` overrides defaultValues passed to `useForm` at first render
See original GitHub issuewatch
method picks up a default value provided to it instead of picking up the values set in useForm
and seems like this happens only at initial render.
This makes it problematic to work with dynamic fields for me.
Here is a Sandbox example: https://codesandbox.io/s/dynamic-custom-fields-f5w03
Note that initially both animals have Cat
type despite the defaultValue for the second animal was set to Dog
in useForm
.
As soon as you click ‘Add animal’ button you’ll see that it gets fixed.
Expected behavior
I’d expect that defaultValue
in watch method will be used only in cases when it wasn’t set in useForm
method.
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
useForm | React Hook Form - Simple React forms validation
The defaultValues prop is used to populate the entire form values. It supports both sync and async set form default values. You can...
Read more >DefaultValues from useForm is not updated correctly with ...
Setting defaultValue via useForm will only set the form values on the initial render. It behaves similar to useState , which will also...
Read more >Create Dynamic Forms in React Using React Hook Forms
React Hook Form minimizes the number of re-renders, minimizes validate ... It will override the defaultValue passed in the useForm hook.
Read more >Final Form Docs – `FieldProps`
A render function that is given FieldRenderProps , as well as any non-API props passed into the <Field/> component. For example, if you...
Read more >React Query and Forms | TkDodo's blog
I have gone on the record already about how I am not a fan of copying ... and because our data is undefined...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
we do check in react hook form input
@bluebill1049 seems like this works smoothly, thanks for the help!