Skip to content

React Hook Form Field Array Not Updating — Fix Dynamic Fields

DodaTech Updated 2026-06-24 2 min read

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

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. 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

### Why should I use field.id as the key instead of index?

When inserting or removing fields, indexes shift. Using index as key causes React to reuse incorrect input state. field.id stays with the field even when indexes change, preserving input values.

How do I handle nested field arrays?

Nest useFieldArray calls. Inside each parent item, create another useFieldArray with a nested name path like parents.${parentIndex}.children.

What happens when I call append?

append adds a new field object with a unique id to the fields array, initialized with the values you pass. The new field appears at the end of the list.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro