【问题标题】:How to change more than 1 state in React-easy-state?如何在 React-easy-state 中更改多个状态?
【发布时间】:2021-05-05 21:18:23
【问题描述】:

我无法使用 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 复制到沙盒。

【问题讨论】:

    标签: reactjs react-state-management react-easy-state


    【解决方案1】:

    您没有任何名为sumNum 的状态。

    // your store
    
    const myStore = store({
      rndNum: "",
      counter: 1,
      someNum: 2, <--- not sumNum
      showRes: false 
    });
    

    将其更改为 someNum 即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2021-10-05
      相关资源
      最近更新 更多