报错信息
Runtime Error
App.js: An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft. (15:4)
12 |
13 | export default function TaskApp() {
14 | const [todos, setTodos] = useImmer(
> 15 | initialTodos
^
16 | );
17 |
18 | function handleAddTodo(title) {
报错代码
function handleAddTodo(title) {
setTodos(todos => todos.push({
id: nextId++,
title: title,
done: false
}))
}
这里的错误是由于setTodos参数中的函数体部分没有用大括号括起来,正确如下:
function handleAddTodo(title) {
setTodos(todos => {
todos.push({
id: nextId++,
title: title,
done: false
})
})
}