React Lists & Keys — Complete Guide
React Lists & Keys — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of React.js Tutorial on Toolliyo Academy.
On this page
React.js Tutorial · Lesson 16 of 100
React Lists & Keys
Beginner → Intermediate → Advanced → Professional
Beginner · 1 — Learn by example · ~6 min · Module 2: Props, Events & Lists
What is this?
Render lists by mapping an array to JSX. Each item needs a unique key prop so React can track which row changed, added, or removed.
Why should you care?
Without keys, React may update the wrong DOM nodes when the list reorders — causing bugs and lost input focus.
See it live — copy this example
Paste into src/App.jsx (or the file noted in the steps). Save and watch the browser update.
const todos = [
{ id: 1, text: 'Buy milk' },
{ id: 2, text: 'Call mom' }
];
<ul>
{todos.map(todo => (
<li key={todo.id}>{todo.text}</li>
))}
</ul>
Run Example »
Edit the code and click Run to see the result update live.
What happened?
- key={todo.id} should be stable and unique among siblings.
- Use database ids, not array index, when items can be reordered or deleted.
Try it yourself
- Map an array to
- or table rows.
- Add key from a unique id field.
- Filter the array before map if needed.
- Change text or labels in the example and save — watch the browser update.
- Break the code on purpose (remove a bracket), read the error message, then fix it.
Remember
Use .map() to render lists. Always add a stable unique key. Prefer id over index when list changes.