Key Prop Purpose
Question
Why does React need the key prop in lists?
Hint
Keys must be unique among siblings and stable.
Explanation
The key prop helps React identify which list items have changed, been added, or removed, enabling efficient DOM updates. Without keys, React uses index by default, which causes bugs when items reorder or are inserted at the beginning. Keys must be unique among siblings and stable across renders (do not use random values or array indices for dynamic lists). Use stable IDs from your data as keys. Keys are internal to React and not accessible in the child component as props.
Related Resources
Related Lessons
- List Rendering
Learn list rendering.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.