All jobs / Frontend / web developer / React
Frontend / web developer interview question · 0–1 years
Why does React warn about a missing key when you render a list?
The strongest answer
Keys let React match each rendered item to its previous version across renders, so reordering, inserting or deleting does not scramble state and DOM; a stable, unique id per item is the right key, not the array index
Why it works
Right. Identity across renders; the index breaks when the list changes order.
What a good answer covers
- Key = stable identity per item.
- Use ids, not the index.
- Index keys break on reorder or delete.
- Keys must be unique among siblings.
Answers that fall short
- Close, but not the strongest: Keys make the list render faster
Correctness first; speed follows. - Weak: Keys are required for CSS
Nothing to do with CSS. - Red flag: It is a linting rule with no effect
Wrong keys cause real bugs — inputs losing text, wrong rows updating.
Who gets asked this
More React questions
- What is a controlled input?
- What is useEffect for?
- What happens if useEffect has an empty dependency array, and if it has none at all?
- How do you render something only when a condition holds?
- Why does onClick={handleClick()} fire during render instead of on click?
- Two sibling components need the same piece of data. Where does it live?
- Why does a component return a fragment instead of a wrapping div?
- Why does items.push(x); setItems(items) not re-render?