在 useState 中保存的数组中包含的一系列对象中增加键的值 (+1)

Increment a key's value (+1) within a series of objects contained in an array that's held in useState

const = [items, setItems] = useState([{ name: "foo", wait: 1 }, { name: "bar", wait: 5 }])

我需要将项中所有对象的键值 wait 增加 1。

这是我到目前为止的尝试...

setItems(items.map(e => [...e, e.wait++]))

我遇到了一些疯狂的错误...我不确定我是否应该使用传播运算符或接近我所拥有的东西。

map 应该 return 对象而不是数组。

const items = [
  { name: "foo", wait: 1 },
  { name: "bar", wait: 5 },
];

const updated = items.map((item) => ({ ...item, wait: item.wait + 1 }));

// setItems(items.map(item => ({...item, wait: item.wait + 1})));

console.log(updated);