From b29b2f76200c36d05c812a8b9a465d2219265d32 Mon Sep 17 00:00:00 2001 From: hmuri Date: Sun, 21 Jul 2024 15:29:29 +0900 Subject: [PATCH] =?UTF-8?q?todoList=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index b428f9a..3570f7f 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,8 @@ import React, { useState } from "react"; function App() { - const [tasks, setTasks] = useState([]); + const [tasks, setTasks] = useState(["자기", "놀기", "먹기"]); + const [doneTasks, setDoneTasks] = useState([]); const [input, setInput] = useState(""); const handleAddTask = () => { @@ -11,6 +12,11 @@ function App() { } }; + const handleDelete = (index) => { + const newTasks = tasks.filter((task, i) => i != index); + setTasks(newTasks); + }; + const handleChange = (event) => { setInput(event.target.value); }; @@ -22,6 +28,15 @@ function App() {
{tasks.map((task, index) => ( +
+ {task} +
handleDelete(index)}> 삭제
+
+ ))} +
+
##################################
+
+ {doneTasks.map((task, index) => (
{task}
))}