React Hook Form Field Array Not Updating — Fix Dynamic Fields
In this fix, you'll learn how to manage dynamic form fields with useFieldArray. This matters for dynamic form sections, and appears in invoice line items and team member forms.
The Problem
The following code demonstrates the typical mistake:
const { fields, append } = useFieldArray({
control,
name: 'items',
});
return (
{fields.map((field, index) => (
<input key={field.id} {...register(`items.${index}.name`)} />
))}
);
// Fields render but values don't submit correctly
The Fix
Here is the corrected version:
const { fields, append, remove } = useFieldArray({
control,
name: 'items',
});
return (
<>
{fields.map((field, index) => (
<div key={field.id}>
<input {...register(`items.${index}.name`)} />
<button onClick={() => remove(index)}>Remove</button>
</div>
))}
<button onClick={() => append({ name: '' })}>Add</button>
</>
);
// Dynamic fields work correctly — values submit as array
Prevention
- Always use field.id as the key (not index) for stable re-renders.
- Use the fields array from useFieldArray — never create your own index-based list.
- Match the name in useFieldArray with register name pattern (arrayName.index.field).
- For nested field arrays, use dot notation in the name.
- Use replace() to reset the entire field array.
Common Mistakes with hook form field array
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging
These mistakes appear frequently in real-world REACT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro