【发布时间】:2021-02-18 02:10:37
【问题描述】:
我点击复选框。当我选中复选框时,我正在尝试更新状态,但它没有立即更新。我创建了一个名为 handleAllCheckbox 的 onchange 事件。
这是我的代码 - const [hello, setHello] = useState(false);
const handleAllCheckbox = (e) => {
setHello(!hello);
if (!hello) {
contactList.map((item) => {
Ids.push(item._id)
});
setTheArray(...theArray, Ids);
}
else {
const newIds = []
setTheArray(...theArray, newIds);
}
}
如果hello 是true,那么theArray 必须有ID,如果它是假的,那么theArray 应该是空的。
【问题讨论】:
标签: reactjs