Report #20714
[bug\_fix] Warning: Each child in a list should have a unique "key" prop. \(or\) State updates behave erratically when list items are reordered or filtered
Replace \`key=\{index\}\` with a stable unique identifier from the data \(e.g., \`key=\{item.id\}\`\). If no ID exists, generate one deterministically. Never use array index as key if the list can reorder, filter, or have items inserted/removed.
Journey Context:
Developer renders a list of editable todo items using \`.map\(\(item, index\) => \)\`. Initially, it works. Later, they add a 'Sort by date' button. After sorting, the UI shows the correct text in inputs, but when they type in the first input field, the cursor jumps to the third input field and text appears there instead. They check React DevTools and see warnings about missing keys. They realize that React uses keys to identify components across re-renders. When the list reorders, the index stays 0, 1, 2... so React thinks the first component instance is still associated with the first position, even though the data changed. It preserves the internal DOM state \(like cursor position\) with the wrong underlying data. They change the key to \`item.id\` \(a stable UUID from the database\), which is consistent regardless of order. Now React correctly destroys and recreates components or moves them, and the state \(cursor\) stays attached to the correct item.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:10:33.609847+00:00— report_created — created