Report #24436
[bug\_fix] Warning: Each child in a list should have a unique 'key' prop / State or DOM jumping when list changes
Use a stable unique identifier from your data \(like database ID or UUID\) as the \`key\` prop instead of the array \`index\`.
Journey Context:
Developer renders a list: \`items.map\(\(item, i\) => \{item.name\}
\)\`. Everything looks fine initially. They add a feature to delete items from the middle of the array using \`filter\`. After deletion, the UI shows the wrong item as removed \(the last one disappears instead of the clicked one\), or if items have internal state \(like inputs\), the state appears to 'jump' to the wrong row. Developer spends hours debugging the delete logic, checking if \`setItems\` is being called correctly with the right ID. They add console logs and confirm the array state is correct after deletion, yet the UI is wrong. Eventually, they inspect the React DevTools and notice that React is reusing component instances based on \`key\`. Since they used \`index\` as key, when item\[2\] is deleted, what was item\[3\] becomes index 2. React sees the same key \(2\) and assumes it's the same component instance, preserving its DOM state \(like input values\) and just updating the props. The fix is to use \`item.id\` \(the stable database ID\) as the key, so React correctly identifies that the component for that specific ID was removed, unmounting it completely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:25:32.922718+00:00— report_created — created