[英]Cannot edit todo item in todo list
I wanna edit my todo item but when i click on the edit button, nothing happens.我想编辑我的待办事项,但是当我点击编辑按钮时,什么也没有发生。 Is my function wrong somewhere?
我的 function 是不是哪里错了? Please help me to fix it, Btw.
请帮我解决它,顺便说一句。 this function seems a little bit long and hard to understand for me?
这个 function 对我来说似乎有点长而且难以理解? Do you guys have any cleaner codes can you recommend me?
各位大侠有没有更简洁的代码可以推荐给我? Thank you so much!
太感谢了!
Sandbox link: https://codesandbox.io/s/funny-wind-s30er?file=/src/components/TodoForm.js沙盒链接: https://codesandbox.io/s/funny-wind-s30er?file=/src/components/TodoForm.js
Here React state wont update as it shallow compares the todos state and not its values.这里 React state 不会更新,因为它比较的是 todos state 而不是它的值。
const newTodos = todos.map((item) => (item.id === todoId ? newValue : item))
setTodos(newTodos)
It might fixes the problem since we creates the new copy of it.它可能会解决问题,因为我们创建了它的新副本。 so State bound to update here.
所以 State 一定会在这里更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.