({
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 value = useWatch({ |
| 31 | name: 'test', |
| 32 | control, |
| 33 | }); |
| 34 | const renderCountRef = React.useRef(0); |
| 35 | renderCountRef.current++; |
| 36 | |
| 37 | return ( |
| 38 | <div> |
| 39 | <div> |
| 40 | {fields.map((item, i) => ( |
| 41 | <Controller |
| 42 | key={item.id} |
| 43 | render={({ field }) => <input {...field} aria-label={'name'} />} |
| 44 | name={`test.${index}.keyValue.${i}.name`} |
| 45 | control={control} |
| 46 | /> |
| 47 | ))} |
| 48 | </div> |
| 49 | |
| 50 | <button |
| 51 | id={`nest-append-${index}`} |
| 52 | type="button" |
| 53 | onClick={() => append({ name: 'append' })} |
| 54 | > |
| 55 | append |
| 56 | </button> |
| 57 | |
| 58 | <button |
| 59 | id={`nest-prepend-${index}`} |
| 60 | type="button" |
| 61 | onClick={() => prepend({ name: 'prepend' })} |
| 62 | > |
| 63 | prepend |
| 64 | </button> |
| 65 | |
| 66 | <button |
| 67 | id={`nest-swap-${index}`} |
| 68 | onClick={() => swap(1, 2)} |
| 69 | type="button" |
| 70 | > |
| 71 | swap |
| 72 | </button> |
| 73 | |
| 74 | <button |
| 75 | id={`nest-move-${index}`} |
nothing calls this directly
no test coverage detected
searching dependent graphs…