React-hook-form checkbox with dynamic array

I am having a bit of a trouble trying to watch a dynamic array checkbox

I have no trouble watching a single checkbox state changes as below:

const useCheckboxWatch = watch('Checkbox1');

where Checkbox1 is the name given to the Checkbox.

I am trying to determine if a given textfield should be read only based on if the given checkbox is checked…

However, with dynamic array fields, I am not sure how I should write this since it will not be possible to write Checkbox[0], Checkbox[1], etc… as the array length is not fixed…

Any help is appreciated…

Simplest solution would be to watch all the inputs, then writing your business logic filtering only when the input you needed changed.

Otherwise did you had a look at useFieldArray.

From the docs:

Custom hook for working with uncontrolled Field Arrays (dynamic inputs).

Hope it helps.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.