react-redux中connect使用裝飾器的方式寫
阿新 • • 發佈:2019-01-08
1.安裝外掛babel-plugin-transform-decorators-legacy
2.npm run eject 彈出react外掛
3.package.json中babel上加入"plugins": ["transform-decorators-legacy"]
"babel": {
"presets": [
"react-app"
],
"plugins": [
"transform-decorators-legacy"
]
},
4.
@connect( state=>({num : state}), {add , remove , addAsync} )
後續報錯 The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean
The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean. If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the 'decorators-legacy' plugin instead of 'decorators'.
解決方案