import type { ReactNode } from 'react'; import { useFieldArray, useFormContext } from 'react-hook-form'; type Props = { name: string; label: string; hint?: string; newItem: () => T; itemLabel?: (index: number) => string; children: (params: { index: number; namePrefix: string }) => ReactNode; }; export function ArrayEditor({ name, label, hint, newItem, itemLabel, children, }: Props) { const { control } = useFormContext(); const { fields, append, remove, move } = useFieldArray({ control, name }); return (

{label}

{hint && (

{hint}

)}
{fields.length === 0 && (
(aucun élément — clique « ajouter » pour commencer)
)}
    {fields.map((field, idx) => (
  1. {itemLabel ? itemLabel(idx) : `# ${String(idx + 1).padStart(2, '0')}`}
    {children({ index: idx, namePrefix: `${name}.${idx}` })}
  2. ))}
); }