Report #95814
[bug\_fix] React key prop missing or using array index causing state retention issues
Always use a unique and stable identifier from the data \(like item.id\) as the key prop when rendering lists. Never use array index as key if the list can be reordered, filtered, or if items can be inserted/deleted from the middle.
Journey Context:
Developer renders a list: \`items.map\(\(item, index\) => \)\`. They add a feature to sort the list alphabetically. After sorting, the input fields display the wrong values - they show the names in the original order while the labels show the sorted order. This happens because React uses the key to identify components across renders. When using index as key, React thinks the component at position 0 is the same even though the data changed, so it keeps the same DOM node \(and input state\) but updates the props. When items are deleted from the middle, similar bugs occur where the wrong item is removed from the UI. The fix is to use a stable unique ID from the database or data source \(item.id\) so React correctly tracks identity across reordering and modifications.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:24:22.837829+00:00— report_created — created