-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathApp.jsx
More file actions
38 lines (32 loc) · 820 Bytes
/
App.jsx
File metadata and controls
38 lines (32 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react'
import TodoList from './TodoList.jsx'
import TodoAddForm from './TodoAddForm.jsx'
const todos = [];
class TodoApp extends React.Component {
state = {
todos: []
}
addTodo = (val) => {
this.setState({
todos: this.state.todos.concat(val),
});
console.log(this.state);
}
deleteTodo = (index) => {
console.log('index:', index);
console.log(this.state.todos.splice(index, 1)); //Array.splice(start, deleteCount) return an array containing the deleted elements
this.setState({
todos: this.state.todos
});
}
render() {
return (
<div>
<h2>Todo App</h2>
<TodoAddForm addTodo={this.addTodo} />
<TodoList todos={this.state.todos} delTodo={this.deleteTodo} />
</div>
);
}
}
export default TodoApp;