安装
yarn add mobx@5 mobx-react@5 -S
yarn add @babel/cli @babel/plugin-proposal-class-properties @babel/plugin-proposal-decorators @babel/plugin-proposal-object-rest-spread @babel/plugin-transform-classes @babel/plugin-transform-flow-strip-types @babel/plugin-transform-runtime @babel/polyfill @babel/preset-env @babel/preset-flow @babel/preset-react babel-loader babel-plugin-import babel-plugin-module-resolver babel-plugin-transform-runtime babel-polyfill babel-preset-es2015 babel-preset-react babel-preset-react-native babel-preset-react-native-stage-0 babel-preset-react-native-syntax -D
配置文件
在 babel.config.js 中配置
module.exports = {
presets: ['module:metro-react-native-babel-preset', '@babel/preset-flow'],
plugins: [
'@babel/transform-flow-strip-types',
['@babel/plugin-proposal-decorators', {legacy: true}],
['@babel/plugin-proposal-class-properties', {loose: true}],
['@babel/plugin-transform-runtime', {}],
['import', {libraryName: '@ant-design/react-native'}],
],
};
使用方式和 react 相同