Menu
Coddy logo textTech

Keys Matter

Part of the Fundamentals section of Coddy's React journey — lesson 36 of 42.

Every element returned from map needs a key, a stable, unique label for that item:

{todos.map((todo) => <li key={todo.id}>{todo.text}</li>)}

Why? When the array changes, React compares the new list with the old one. Keys tell it which item is which, so it moves elements instead of rebuilding them, keeping state, focus and animations intact.

Best key: a real id from your data. Acceptable: any value unique and stable per item (like our fruit names). Last resort: the array index. It breaks reordering, because position isn't identity.

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals