Keys are unique identifiers for elements in a list that help React understand which element is which during updates.
Simple analogy: Imagine you are arranging books on a shelf. Each book has an ISBN (key). When you:
Without keys React will think: "All books are new! I'll delete everything and redraw." With keys: "Ah, this is the same book, just moved."
Key rules:
1todos.map((todo, index) => <TodoItem key={index} />);2todos.map(todo => <TodoItem key={todo.id} />);
What key should be:
When index is acceptable:
Important: If you change the key — React will create a new component "from scratch" (reset state).