【发布时间】:2021-10-19 12:37:46
【问题描述】:
我想在按下按钮时从待办事项列表中删除所有已完成的项目。
我怎么能那样做?我的useState 是这样的:
const [todos, setTodos] = useState([
{ id: 58477, text: "Wash dishes", done: false },
{ id: 64851, text: "Bake a cake", done: true },
{ id: 59858, text: "Make a website", done: true },
])
我的代码是这样的:
export default function TodoListItem(){
const [ todos, setTodos ] = useTodosContext()
function deleteTodo(todo) {
console.log("Clear completed")
}
return(
<div>
{todos.map(todo => <li><input type="checkbox" className="roundCheckBox"/>{todo.text}</li>)}
<button onClick={() => deleteTodo(todo)}>CLEAR COMPLETED</button>
</div>
)
}
【问题讨论】: