updated key logic

This commit is contained in:
Micah Godbolt
2019-02-13 14:13:57 -08:00
parent 5d3c0983dd
commit 24733636ec
3 changed files with 33 additions and 16 deletions
+1 -3
View File
@@ -31,11 +31,9 @@ export class TodoApp extends React.Component<any, any> {
_addTodo = () => {
const { todos, inputValue } = this.state;
const id = todos[0] ? todos[0].id + 1 : 0;
const newTodos = [
{
id: id,
key: id,
id: todos[0] ? todos[0].id + 1 : 0,
text: inputValue
},
...todos
+2 -2
View File
@@ -13,9 +13,9 @@ export class TodoList extends React.Component<any, any> {
return filter == 'all' || matchesActive || matchesCompleted;
})
const TodoListItems = filteredTodos.map((todo, i) => {
const TodoListItems = filteredTodos.map((todo) => {
return (
<TodoListItem onTodoToggle={onTodoToggle} {...todo} />
<TodoListItem key={todo.id} onTodoToggle={onTodoToggle} {...todo} />
);
})