我们在使用react-redux插件时候,connect函数的一般用法
上面的写法是可以的,没问题的,但是B格方面略低了一点,于是我们用到了es7的装饰器函数@connect
不进行相关配置的话,会报错 syntax 'decorators-legacy' isn't currently enabled
于是我们要进行以下的配置
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-decorators": "^7.13.5",
"babel-plugin-import": "^1.13.3",
"customize-cra": "^1.0.0",
"react-app-rewired": "^2.1.8"
然后在根目录下增加一个配置文件
const { override,addDecoratorsLegacy } = require('customize-cra')
module.exports = override(
addDecoratorsLegacy()
);
最好修改相关的scripts命令
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},
即可完美运行@装饰器类