Report #9646
[bug\_fix] Each child in a list should have a unique 'key' prop / Warning: Encountered two children with the same key / State resets or jumps when list reorders
Use a stable, unique identifier from your data model \(like a database ID, UUID, or slug\) as the \`key\` prop. Never use the array index as the key if the list can reorder, items can be inserted/deleted from the middle, or if item state must persist across renders. If no stable ID exists, generate one from content hashes or use a library like \`uuid\` during data creation.
Journey Context:
Developer renders a todo list: \`todos.map\(\(todo, index\) => \)\`. Everything looks fine until they implement a 'Delete' button. When deleting the second item in a list of three, the UI removes the last item visually instead of the second, though the data is correct. Worse, if \`TodoItem\` has internal state \(like an 'editing' boolean\), the state persists on the wrong item after reordering. Developer checks React DevTools and notices keys are 0, 1, 2. After deletion of index 1, the remaining items now have indices 0 and 1 \(previously 0 and 2\), so React thinks the item at index 1 was removed, not the specific item with ID 456. Developer reads that keys must be stable identities. Changes to \`key=\{todo.id\}\` using the database primary key. Now when item with ID 456 is deleted, React correctly identifies it by key and removes the correct DOM node regardless of array position. State now stays attached to the correct item. Developer also learns the pattern of using \`key\` to reset component state when props change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:44:18.721597+00:00— report_created — created