Props9 / 12
Up next

Key prop on lists

interface Todo {
  id: number;
  text: string;
}

function TodoList({ todos }: { todos: Todo[] }) {
  return (
    <ul>
      {todos.map((todo) => (
        // key must be stable and unique among siblings
        <li key={todo.id}>{todo.text}</li>
      ))}
    </ul>
  );
}

export default TodoList;
What you're solving

give each mapped element a stable key