【问题标题】:How to use MobX with decorators in React Native 0.57?如何在 React Native 0.57 中使用 MobX 和装饰器?
【发布时间】:2019-03-16 10:58:05
【问题描述】:

我在我的 react-native 应用程序中使用 MobX。

升级到 0.56 后,我使用了以下答案中提供的解决方案:https://stackoverflow.com/a/51234815/5597641

但是,它不再适用于 0.57。有关.babelrc 配置的任何想法都会有所帮助...

【问题讨论】:

    标签: react-native decorator babeljs mobx


    【解决方案1】:

    一段时间后,我找到了一个可以让 MobX 与 React Native 0.57 一起工作的配置。问题在于 0.57 中引入的新 module:metro-react-native-babel-preset。我们需要使用@babel/plugin-transform-flow-strip-types 插件来解决这个问题...

    这是有效的.babelrc 配置

    { 
      "presets": ["module:metro-react-native-babel-preset"],
      "plugins": [
            ["@babel/plugin-transform-flow-strip-types"],
            ["@babel/plugin-proposal-decorators", { "legacy": true}],
            ["@babel/plugin-proposal-class-properties", { "loose": true}]
        ]
    }
    

    和package.json 依赖:

    "dependencies": {
        "babel-plugin-transform-flow-strip-types": "^6.22.0",
        "mobx": "^5.5.0",
        "mobx-react": "^5.2.8",
        "mobx-state-tree": "^3.5.0",
        "native-base": "^2.8.1",
        "react": "16.5.0",
        "react-native": "0.57.1",
      },
      "devDependencies": {
        "@babel/plugin-proposal-class-properties": "^7.1.0",
        "@babel/plugin-proposal-decorators": "^7.1.2",
        "babel-jest": "23.6.0",
        "jest": "23.6.0",
        "metro-react-native-babel-preset": "0.48.0",
        "react-test-renderer": "16.5.0"
      }
    

    安装所需的依赖项后,请按照以下评论中的 解决方法 2 https://github.com/facebook/react-native/issues/20150#issue-340235017

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-07
      • 2017-01-08
      相关资源
      最近更新 更多