Replies: 1 comment 1 reply
-
const { register, handleSubmit } = useForm<FormValues>({
defaultValues: {
"info.firstName": "bill"
}
});
We don't convert your default values into nested object path. |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
Version Number
7.43.3
Codesandbox/Expo snack
https://codesandbox.io/s/focused-microservice-cjinms?file=/src/App.tsx
Steps to reproduce
defaultValues
inuseForm
and the bottom one usesuseController
to set adefaultValue
. Both forms log values to the console when submitted"info.firstName"
key as well as aninfo: { firstName }
keyinfo: { firstName }
keyExpected behaviour
It seems like in most cases, like
useController
, providing an input name with dot notation sets up the form values state as a nested object. But when usinguseForm
and providing dot notation indefaultValues
, the form values that get set up are a flat object, not a nested object.Is it intentional that
useForm
works differently for setting up form values compared touseController
? It seems like possibly a bug to me, but perhaps there are reasons why this is set up this way, or maybe I am misunderstanding the intended usage of dot notation in react-hook-form?What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions