-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
35 lines (28 loc) · 968 Bytes
/
App.tsx
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
import { useRef, useState } from 'react';
import { TodoType } from '@components/Todo';
import Todos from '@components/Todos';
import TodosPresenter from '@presenters/todosPresenter';
const todosPresenter = new TodosPresenter([{ id: 1, title: 'ㅎㅇ' }]);
const App: React.FC = () => {
const inputRef = useRef<HTMLInputElement>(null);
const [todos, setTodos] = useState<TodoType[]>(todosPresenter.getTodos());
const handleClickDeleteTodo = (todoId) => {
todosPresenter.delete(todoId, setTodos);
};
const handleClickAddTodo = () => {
if (!inputRef.current) return;
const title = inputRef.current.value;
todosPresenter.add(title, setTodos);
};
return (
<div>
<h1>Hello World</h1>
<input ref={inputRef} type="text" />
<button type="button" onClick={handleClickAddTodo}>
생성
</button>
<Todos todos={todos} onClickDeleteTodo={handleClickDeleteTodo} />
</div>
);
};
export default App;