Mobx + React不会更新渲染组件

时间:2018-11-12 11:44:18

标签: javascript reactjs mobx

我正在使用mobx打开和关闭弹出模式(带有react)

不幸的是,状态更改未反映在弹出模式中。可能是什么问题?

编辑:我添加了一个带有更简单示例的沙箱:https://codesandbox.io/s/7z161kyv86

1 个答案:

答案 0 :(得分:2)

decorate不起作用,因为Babel 7如何转换类属性。

Babel 7

class Foo {
  value = 1;
}

// =>

class Foo {
  constructor() {
    Object.defineProperty(this, "value", {
      configurable: true,
      enumerable: true,
      writable: true,
      value: 1
    });
  }
}

您需要将@babel/plugin-proposal-class-properties插件配置为使用loose模式,以与Babel 6相同的方式对其进行转换。

.babelrc

{
  "plugins": [
    [
      require('@babel/plugin-proposal-class-properties').default,
      {
        loose: true
      }
    ]
  ]
}

通天塔6

class Foo {
  value = 1;
}

// =>

class Foo {
  constructor() {
    this.value = 1;
  }
}
相关问题