-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.jsx
65 lines (57 loc) · 1.32 KB
/
App.jsx
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { useState, useRef } from "react";
import Header from "./component/Header"
import TodoEditor from "./component/TodoEditor";
import TodoList from "./component/TodoList";
import './App.css';
const mockTodo = [
{
id: 0,
content: "리액트 express 공부하기",
createDate: new Date().getTime(),
isDone: false,
},
{
id: 1,
content: "figma 디자인 완료하기",
createDate: new Date().getTime(),
isDone: false,
},
{
id: 2,
content: "node.js 공부하기",
createDate: new Date().getTime(),
isDone: false,
},
]
function App() {
const [todo, setTodo] = useState(mockTodo);
const idRef = useRef(3);
const onCreate = (content) => {
const newItem = {
id: idRef.current,
content,
isDone: false,
createDate: new Date().getTime(),
};
setTodo([newItem, ...todo]);
idRef.current += 1;
}
const onUpdate = (targetId) => {
setTodo(
todo.map((it) =>
it.id = targetId ? {...it, isDone: !it.isDone } : it
)
)
}
const onDelete = (targetId) => {
setTodo(todo.filter((it) => it.id !== targetId));
}
return (
<div className="App">
<Header />
<TodoEditor onCreate={onCreate} />
<TodoList todo={todo} onUpdate={onUpdate} onDelete={onDelete}/>
</div>
);
}
export default App;