[英]Update object state by using hooks
I have a question about changing the value of a property within an object using Hooks, How do I do that?我有一个关于使用 Hooks 更改 object 中的属性值的问题,我该怎么做?
const [user, setUser] = useState({id: '', name: '', email: '', entries: 0, joined: ''})
let count = 5;
And I would like to update the value of the property"entries" with a variable "count".我想用变量“count”更新属性“entries”的值。
How do I do that with setUser?我如何使用 setUser 做到这一点?
Thanks谢谢
This should work;这应该有效;
setUser({
...user,
entries: count
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.