mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-07-12 15:18:34 +08:00
updated key logic
This commit is contained in:
+1
-3
@@ -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
|
||||
|
||||
@@ -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} />
|
||||
);
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user