-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (39 loc) · 930 Bytes
/
index.js
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
39
40
41
42
43
function App(){
const [todos, setTodos] = React.useState([
{
text: 'learn react',
isCompleted: false,
},
{
text: 'meet friend for lunch',
isCompleted: false,
},
{
text: 'build todo app',
isCompleted: false,
}
]);
const addTodo = text => {
const newTodos = [...todos, {text, isCompleted:false}];
setTodos(newTodos);
}
const removeTodo = index => {
let temp = [...todos];
temp.splice(index, 1);
setTodos(temp);
}
return(
<div className="app">
<div className="todo-list" >
{todos.map((todo, i) => (
<Todo key={i} index={i} todo={todo} remove={removeTodo}/>
))}
<TodoForm addTodo={addTodo} />
</div>
</div>
);
}
ReactDOM.render(
<App/>,
document.getElementById('root')
);