Setting default value
See original GitHub issueDescribe the bug
When taking the form methods by using useForm<Type>({ defaultValues: values })
, I cannot get values by using getValues()
To Reproduce Steps to reproduce the behavior:
- Get form methods from
useForm<Type>({ defaultValues: values })
- Use
<FormProvider {...formMethods}>{children}</FormProvider>
- Get values from
useFormContext
inside a nested component - And the values will be
{}
Codesandbox link (Required) https://codesandbox.io/s/brave-wescoff-s8i8k
Expected behavior
getValues()
method had to return default values as I had provided them
Desktop (please complete the following information):
- OS: macOS Catalina
- Browser: Chrome v84.0.4147.89
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:39 (22 by maintainers)
Top Results From Across the Web
SQL DEFAULT Constraint - W3Schools
The DEFAULT constraint is used to set a default value for a column. The default value will be added to all new records,...
Read more >Set a Default Value - CustomGuide
In Design View, click the field you want to add a default value to. · Click the Default Value box. · Enter the...
Read more >3 Ways to Set Default Value in JavaScript | SamanthaMing.com
Let's break down the 3 different ways to set Default Values using logical operator, ternary, and if/else...
Read more >Set a Field's Default Value in an MS Access Table –
A default value is automatically entered in a field for a new record. You can set a default value for table fields set...
Read more >SQL Default Value: How To with Examples - Database Star
Setting a default value in SQL can be done when you create the table or on an existing table's column. The default value...
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
looks like everyone is expected getValues to return defaultValues, we will sort it out then.
In case it is useful, I’ve been getting around this by merging in the defaults with the current value by accessing the ref via control. It’s not necessarily conventional but it works.
Obviously I’m just merging single depths here as I don’t use any dot notation but you could just as easily use
values = deepmerge(...)
for example.