09. TODO APP (DELETE)
Todo APP 을 만들어봅니다
들어가기전에
실습
Delete Function 추가
// App.js
import React, { useState } from "react";
import Header from "./components/header";
import Contents from "./components/contents";
import Footer from "./components/footer";
function App() {
const [todos, setTodos] = useState([]);
const handleAdd = text => {
setTodos([
...todos,
{
id: Date.now(),
text,
isDone: false
}
]);
};
const handleDelete = id => { // Contents 에게 넘겨줄 todo 를 삭제하는 함수
setTodos(todos.filter(todo => todo.id !== id));
};
return (
<div>
<Header onChange={handleAdd} />
<Contents todos={todos} onDelete={handleDelete} />
<Footer />
</div>
);
}
export default App;Todo 삭제

Last updated
Was this helpful?