使用@connec的时候有报错:
- Support for the experimental syntax 'decorators-legacy' isn't currently enabled
- Please use
export @dec class
instead
- create-react-app中使用@connect修饰器出现不支持的情况
安装依赖:
- yarn add @babel/plugin-proposal-decorators
- yarn add babel-plugin-transform-decorators-legacy
修改文件:
// 代码片段
{
"babel": {
"presets": [ "react-app" ],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true } ], // 增加配置
[ "@babel/plugin-proposal-class-properties", { "loose": true } ] // 增加配置
]
}
}
高阶组件的写法:
- 高阶组件 结合redux( @connect 修饰器 ),本人文章里面有 可以翻阅
export const wrapAuth = ComposedComponent => {
@connect class AuthButton extends Component{
}
return AuthButton
}
网友评论