({
control,
index,
}: {
control: Control<FormValues>;
index: number;
})
| 16 | }; |
| 17 | |
| 18 | function NestedArray({ |
| 19 | control, |
| 20 | index, |
| 21 | }: { |
| 22 | control: Control<FormValues>; |
| 23 | index: number; |
| 24 | }) { |
| 25 | const { fields, append, prepend, swap, move, remove, insert, update } = |
| 26 | useFieldArray<FormValues, 'test.0.keyValue'>({ |
| 27 | name: `test.${index}.keyValue` as 'test.0.keyValue', |
| 28 | control, |
| 29 | }); |
| 30 | const { touchedFields, dirtyFields } = useFormState({ |
| 31 | control, |
| 32 | }); |
| 33 | const renderCountRef = React.useRef(0); |
| 34 | renderCountRef.current++; |
| 35 | |
| 36 | return ( |
| 37 | <div> |
| 38 | <ul> |
| 39 | {fields.map((item, i) => ( |
| 40 | <Controller |
| 41 | key={item.id} |
| 42 | render={({ field }) => <input {...field} aria-label={'name'} />} |
| 43 | name={`test.${index}.keyValue.${i}.name`} |
| 44 | control={control} |
| 45 | /> |
| 46 | ))} |
| 47 | </ul> |
| 48 | |
| 49 | <div id={`dirty-nested-${index}`}>{JSON.stringify(dirtyFields)}</div> |
| 50 | <div id={`touched-nested-${index}`}>{JSON.stringify(touchedFields)}</div> |
| 51 | |
| 52 | <button |
| 53 | id={`nest-append-${index}`} |
| 54 | type="button" |
| 55 | onClick={() => append({ name: 'append' })} |
| 56 | > |
| 57 | append |
| 58 | </button> |
| 59 | |
| 60 | <button |
| 61 | id={`nest-prepend-${index}`} |
| 62 | type="button" |
| 63 | onClick={() => prepend({ name: 'prepend' })} |
| 64 | > |
| 65 | prepend |
| 66 | </button> |
| 67 | |
| 68 | <button |
| 69 | id={`nest-swap-${index}`} |
| 70 | onClick={() => swap(1, 2)} |
| 71 | type="button" |
| 72 | > |
| 73 | swap |
| 74 | </button> |
| 75 |
nothing calls this directly
no test coverage detected
searching dependent graphs…