Javascript 使用useState更新对象数组中的值
我有一个对象数组,我想使用useState钩子更新这些对象中的一个值,但不清楚如何格式化并使其工作Javascript 使用useState更新对象数组中的值,javascript,reactjs,react-hooks,Javascript,Reactjs,React Hooks,我有一个对象数组,我想使用useState钩子更新这些对象中的一个值,但不清楚如何格式化并使其工作 setCarUnsubscribeList(carUnsubscribeList => (carUnsubscribeList.forEach((car:CarSelections) => { car.checked = true; }))); 展开原始对象并更改所需的属性 setAllChecked(prev => prev.map(car =>({ ...
setCarUnsubscribeList(carUnsubscribeList => (carUnsubscribeList.forEach((car:CarSelections) => {
car.checked = true;
})));
展开
原始对象并更改所需的属性
setAllChecked(prev => prev.map(car =>({
...car,
checked : true
})))
是否出现任何错误?我使用TypeScript,并且在使用此格式时出现此错误:“Type'void'不可分配给Type'CarSelections[]”。