问题描述
我无法使用 React-easy-state
通过一个函数改变 1 个以上的状态我在以下示例中使用了 batch
,并且还单独使用了变更。然而,代码不知何故忽略了我的第二个状态。
代码如下:
batch(() => {
// batch is used to test out whether it will trigger both store changes.
store.counter = store.counter + 1;
store.sumNum = 10; // this is never updated/mutated.
});
用于复制 link 到沙箱。
解决方法
您没有任何名为 sumNum
的状态。
// your store
const myStore = store({
rndNum: "",counter: 1,someNum: 2,<--- not sumNum
showRes: false
});
将其更改为 someNum
即可。