Hi there, i want to know if there is a way to handleChange for every field or form
Closed this issue · 1 comments
Alejomast commented
hello, thank you for your attention, i have this:
const formArray = [
{
type: 'checkbox',
name: '1',
label: '1',
},
{
type: 'checkbox',
name: '2',
label: '2',
},
}
What i am looking for is, when check checkbox 2, i want to dinamically check or uncheck checkbox 1, i have seen from react hook form that i can change value of form with SetValues, but i dont know how to handle this unique change :v
PD: nice lib, very easy usage
fateh999 commented
@Alejomast
Sorry for the late response.
Actually this can be done pretty easily, you just need to follow the React Hook Form watch and setValue method.
e.g.:
const form = useForm():
useEffect(() => {
form.setValue('1', !form.watch('2'))
},[form.watch('2')]);