React Developer interview question · Most asked
Explain React concept: keys in lists.
Summary
Keys give React stable identity for list items during reconciliation.
Longer Answer
When rendering arrays, React uses keys to match previous and next children so it can preserve state and update the right DOM nodes. A good key is stable, unique among siblings, and tied to the data identity, such as a database ID.
Using array indexes as keys is risky when items can be inserted, removed, sorted, or filtered because state can stick to the wrong visual row. Index keys are acceptable only for static lists that never reorder or change length.
Key Points
- When rendering arrays, React uses keys to match previous and next children so it can preserve state and update the right DOM nodes
- A good key is stable, unique among siblings, and tied to the data identity, such as a database ID
- Using array indexes as keys is risky when items can be inserted, removed, sorted, or filtered because state can stick to the wrong visual row
- For 'Explain React concept: keys in lists.', the key is to explain what problem the concept solves, where it fits in React's rendering model, and what mistake causes production bugs.
Using array indexes as keys is risky when items can be inserted, removed, sorted, or filtered because state can stick to the wrong visual row. Index keys are acceptable only for static lists that never reorder or change length
Comparison / Tradeoffs
| Aspect | Notes |
|---|---|
| Core idea | Keys give React stable identity for list items during reconciliation. |
| Practical tradeoff | For 'Explain React concept: keys in lists.', the key is to explain what problem the concept solves, where it fits in React's rendering model, and what mistake causes production bugs. |
Using array indexes as keys is risky when items can be inserted, removed, sorted, or filtered because state can stick to the wrong visual row. Index keys are acceptable only for static lists that never reorder or change length. |
Explanation
Summary
Keys give React stable identity for list items during reconciliation.
Longer Answer
For 'Explain React concept: keys in lists.', the key is to explain what problem the concept solves, where it fits in React's rendering model, and what mistake causes production bugs.
Using array indexes as keys is risky when items can be inserted, removed, sorted, or filtered because state can stick to the wrong visual row. Index keys are acceptable only for static lists that never reorder or change length.
Key Points
- For 'Explain React concept: keys in lists.', the key is to explain what problem the concept solves, where it fits in React's rendering model, and what mistake causes production bugs
- Using array indexes as keys is risky when items can be inserted, removed, sorted, or filtered because state can stick to the wrong visual row
- Index keys are acceptable only for static lists that never reorder or change length
- Use the answer to connect the concept back to a realistic production or interview scenario for 'Explain React concept: keys in lists.'
Comparison / Tradeoffs
| Aspect | Notes |
|---|---|
| Core idea | Keys give React stable identity for list items during reconciliation. |
| Practical tradeoff | In an interview, relate 'Explain React concept: keys in lists.' to implementation decisions, tradeoffs, and operational impact. |
More most-asked React Developer questions
- Explain React concept: state.
- Explain React concept: controlled vs uncontrolled inputs.
- Explain React concept: unidirectional data flow.
- Explain React concept: lifting state up.
- What does `useState` do and when should you use it?
- What does `useEffect` do and when should you use it?
- What does `useContext` do and when should you use it?
- What does `useRef` do and when should you use it?