Why react-hook-form need onChange if it is using ref for accessing value #7019
-
|
I am bit confused. we are passing both the ref and also onChange. Under the hood how a typical input works |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hello @sant527, You don't need to use both at the same time. You can use any one for registering inputs. If you wish to use ref then you need to use this like:
otherwise, you can use onChange method to get and validate values by creating your own function or use the pre-defined one. |
Beta Was this translation helpful? Give feedback.
Hello @sant527,
You don't need to use both at the same time. You can use any one for registering inputs.
If you wish to use ref then you need to use this like:
ref={register}and if you wish to validate your fields on onChange too then simply put this as mode like this:const methods = useForm({ defaultValues: user, mode: 'onChange', resolver: yupResolver(validationSchema(translation)), })const { handleSubmit, reset, register, formState: { errors }, } = methodsotherwise, you can use onChange method to get and validate values by creating your own function or use the pre-defined one.