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