在反应挂钩中更新状态(添加新对象)
Updating state in react hooks (adding new object)
我被困在更新状态中,我现在正在使用一个函数从第 3 方框架中概括模态,当我想更新特定变量时我被卡住了,因为动态它没有更新,即:Ex : setModalState(...oldstate,v1:{v2:false}} 。这里 ${v1} 和 ${v2} 已经处于旧状态,我传递给函数作为道具,但 javascript 没有接受 insted 接受v1,v2;
我附上几张照片以供理解
https://res.cloudinary.com/df2q7cryi/image/upload/v1615998821/error3_svxlcw.png
https://res.cloudinary.com/df2q7cryi/image/upload/v1615998764/eroor2_enjcbc.png
https://res.cloudinary.com/df2q7cryi/image/upload/v1615998762/eroor_bz5wwf.png
解决方法是使用 | setModalState({...modalstate,[section]:{[purpose]:false}})}
参考:.
我被困在更新状态中,我现在正在使用一个函数从第 3 方框架中概括模态,当我想更新特定变量时我被卡住了,因为动态它没有更新,即:Ex : setModalState(...oldstate,v1:{v2:false}} 。这里 ${v1} 和 ${v2} 已经处于旧状态,我传递给函数作为道具,但 javascript 没有接受 insted 接受v1,v2; 我附上几张照片以供理解
https://res.cloudinary.com/df2q7cryi/image/upload/v1615998821/error3_svxlcw.png
https://res.cloudinary.com/df2q7cryi/image/upload/v1615998764/eroor2_enjcbc.png
https://res.cloudinary.com/df2q7cryi/image/upload/v1615998762/eroor_bz5wwf.png
解决方法是使用 | setModalState({...modalstate,[section]:{[purpose]:false}})}
参考:.