From cad84259f70dc91a64aa25665f72e0cbb904aabd Mon Sep 17 00:00:00 2001 From: ongheong Date: Mon, 7 Oct 2024 19:59:18 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Feat:=20App.jsx=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.jsx | 93 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 23 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index aa4d827..0d23a90 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -14,49 +14,96 @@ export default function App() { initialTodos ); + const [isEdit, setIsEdit] = useState(false); + const [name, setName] = useState("고윤정"); + const [major, setMajor] = useState("창의소프트학부 디자인이노베이션"); + const [email, setEmail] = useState("jejukyj@naver.com"); + const [github, setGitHub] = useState("github.com/jejukyj") + function handleAddTodo(title) { - todos.push({ - id: nextId++, - title: title, - done: false - }); + setTodos([ + ...todos, + { + id: todos.length, + title: title, + done: false, + }, + ]); } function handleChangeTodo(nextTodo) { - const todo = todos.find(t => - t.id === nextTodo.id - ); - todo.title = nextTodo.title; - todo.done = nextTodo.done; + const newTodos = todos.map(todo => { + if (todo.id === nextTodo.id) { + return nextTodo; + } else { + return todo; + } + }); + setTodos(newTodos); } function handleDeleteTodo(todoId) { - const index = todos.findIndex(t => - t.id === todoId - ); - todos.splice(index, 1); + let newTodos = todos.filter(p => p.id !== todoId); + setTodos(newTodos); } - return ( <> -
-

안녕하세요, 프론트엔드 개발자 고윤정입니다.

+ { + e.preventDefault(); + setIsEdit(!isEdit); + }}> +

안녕하세요, 프론트엔드 개발자 {' '} + {isEdit ? ( + { + setName(e.target.value) + }} + /> + ) : ( + {name} + )} + 입니다.