diff --git a/src/App.js b/src/App.js
index ae5ce50..8d7aa9f 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,58 @@
+import { useState } from 'react';
import Form from './components/Form';
import Item from './components/Item';
function App() {
+ const [todos, setTodos] = useState([]);
+ const [deleteComplete, setdeleteComplete] = useState(false);
+ const addTodo = newTodo => {
+ const newId = todos.length > 0 ? todos[0].id + 1 : 1;
+ setTodos([{ id: newId, text: newTodo, isCompleted: false }, ...todos]);
+ setdeleteComplete(false);
+ };
+
+ const deleteTodo = id => {
+ setTodos(todos.filter(todo => todo.id !== id));
+ setdeleteComplete(true);
+ };
+
+ const completeTodo = (id, isCompleted) => {
+ setTodos(
+ todos.map(todo => (todo.id === id ? { ...todo, isCompleted } : todo)),
+ );
+ };
+
+ const deleteAll = () => {
+ setTodos([]);
+ setdeleteComplete(true);
+ };
return (
Todo List
-
-
+
+ {todos.length === 0 ? (
+
{deleteComplete ? '할 일이 없습니다.' : '할 일이 없습니다.'}
+ ) : (
+
+
+ {todos.map(todo => (
+
+ ))}
+
+
+
+ )}
);
}
-export default App;
+export default App;
\ No newline at end of file
diff --git a/src/components/Form.js b/src/components/Form.js
index cb405e1..259a911 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -1,10 +1,29 @@
+form
+import { useState } from 'react';
import PropTypes from 'prop-types';
function Form({ onAddTodo }) {
+ const [toDo, setTodo] = useState('');
+ const AddToDo = () => {
+ if (toDo === '') return;
+ onAddTodo(toDo);
+ setTodo('');
+ };
+ const doList = value => {
+ const lists = value.target.value;
+ setTodo(lists);
+ };
return (
-
-
+
+
);
}
@@ -17,4 +36,4 @@ Form.propTypes = {
onAddTodo: PropTypes.func.isRequired,
};
-export default Form;
+export default Form;
\ No newline at end of file
diff --git a/src/components/Item.js b/src/components/Item.js
index a4bd48e..a262491 100644
--- a/src/components/Item.js
+++ b/src/components/Item.js
@@ -3,10 +3,16 @@ import PropTypes from 'prop-types';
function Item({ id, todo, isCompleted, onDeleteTodo, onCompleteTodo }) {
return (
-
- {todo}
+ onCompleteTodo(id, !isCompleted)}
+ />
+ {todo}
-
+
);
@@ -29,4 +35,4 @@ Item.propTypes = {
onCompleteTodo: PropTypes.func.isRequired,
};
-export default Item;
+export default Item;
\ No newline at end of file