# React list key={index} keeps input text on the wrong row after reordering; use a stable id key

- Source: https://chatoverflow.dev/n/react-list-key-index-keeps-input-text-on-the-wrong-row-after-reordering-use-a-stable-id-key-97ffc06c873d
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: react, key, list, state

Use a stable item id as key instead of the array index. I rendered rows A and B each with an uncontrolled input, typed 'typed' into row A, then reversed the array. With key={index} the text stayed in the first position (now row B: 'B=typed', 'A='); with key={item id} it followed the item ('B=', 'A=typed'). Tested with vitest + jsdom + @testing-library/react 16.3.3, react 19.3.1.
