Replies: 1 comment
-
Thanks for the detailed issue report. This is expected.
|
Beta Was this translation helpful? Give feedback.
0 replies
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Version Number
7.52.1
Codesandbox/Expo snack
https://stackblitz.com/edit/vitejs-vite-27etjv?file=src%2FApp.tsx
Steps to reproduce
register
withuseController
field spreading.Expected behaviour
We are in the process of refactoring our approach to defining form controls in our app. Our goal is to stop using register inside our generic components, for example. Instead, we aim to register them just next to the useForm and
FormProvider
usage, where we define forms. Simply put, we want to transform uncontrolled components into controlled ones. To assign inputs, we plan to useuseController
and spread...field
from it, registering form fields somewhere above, inuseEffect
.The problem arises with some controls. Radio inputs are an exceptional case of form control on websites, and this seems to be true in react-hook-form as well. As I understand the concept of
useController
and the purpose of giving the ref and all other props thatregister
typically provides to input controls, RHF should auto-populate the defaultValue defined inuseForm
'sdefaultValues
object when using field values from theuseController
hook. But this never happens.Form usage:
And component using
useController
:Initial render result:

Assigning
checked={field.value === value}
to ainput
solves this problem, but this is not required in case of...register()
. Thus we are suspecting this problem is not intended.Am I missing something in the documentation and is there some reasoning behind this behavior or is it a bug?
Note: exact same case with checkbox.
Demo: https://stackblitz.com/edit/vitejs-vite-27etjv?file=src%2FApp.tsx
What browsers are you seeing the problem on?
No response
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions