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} + )} + 입니다.