Using the array index
suggest changeIf you don’t have stable ids, you can use the numeric index as a last resort. Index keys break down when the list is reordered, filtered, or has items inserted at the front, because React then reuses the wrong component state.
render() {
const { todos } = this.props;
return (
<ul>
{ todos.map((todo, index) =>
<li key={ `todo-${index}` }>
{ todo.text }
</li>
}
</ul>
);
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents