【发布时间】:2021-06-03 08:42:47
【问题描述】:
我在尝试更新状态时遇到问题。 这是我的代码:
const [todos, setTodos]= useState([])
useEffect(() => {
setTodos([
{id:1, title: '',
notes: [{id: 1, description: 'this is a simple description'}]}
])
}, [])
我的目标是在待办事项数组中添加一个注释。 我试试这样
const i = todos.findIndex((t) => t.id === parseInt(id));
const newArr = todos[i].notes[0].push(note);
setTasks(newArr);
但它不起作用 newArr 为我提供了新状态的索引说明。 请帮忙 提前致谢
【问题讨论】:
标签: reactjs react-hooks react-component react-state