[英]Update value in object array with useState
I have an array of objects and I want to update a value within those objects using the useState hook, but unclear on how to format this and get it working.我有一个对象数组,我想使用 useState 钩子更新这些对象中的一个值,但不清楚如何格式化它并让它工作。
setCarUnsubscribeList(carUnsubscribeList => (carUnsubscribeList.forEach((car:CarSelections) => {
car.checked = true;
})));
spread
the original object and change the propert you want spread
原 object 并更改您想要的属性
setAllChecked(prev => prev.map(car =>({
...car,
checked : true
})))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.