MohitDecodes
Back to blogsReact

Why Using Array Index as a React Key Breaks Forms and State

October 22, 2026 · 5 min read

Every React beginner silences the "Each child in a list should have a unique key prop" warning by passing `key={index}`. Everything seems fine until the list supports sorting, filtering, or deleting rows.

What React actually uses keys for

During reconciliation, React matches elements between the previous render and the next render using `key`. If you delete item `0`, the old item at index `1` shifts to index `0` — so React thinks the first component simply stayed there and received updated props, while keeping its old internal input state or animation state!

// Bad when list can reorder or delete
{items.map((item, index) => <Row key={index} item={item} />)}

// Good: stable ID from your data
{items.map((item) => <Row key={item.id} item={item} />)}

Also never generate `key={Math.random()}` during render — that creates a brand-new key on every render, forcing React to unmount and remount every single row on every state change.