- 使用修饰器
安装依赖,注意babel版本号。
npm install @babel/plugin-proposal-decorators --save
配置babel
"babel": { "plugins": [ [ "@babel/plugin-proposal-decorators", { "legacy": true } ] ] },
使用connect:
import React from 'react'; import { connect } from 'react-redux'; import { updatName } from '../redux/name'; @connect( state => state.user, { updatName } ) class Demo extends React.Component{ } export default Demo;
- 按需加载antd
引入依赖
npm install babel-plugin-named-asset-import --save
配置babel
"babel": { "presets": [ "react-app" ], "plugins": [ ["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }] ] }
使用
import { Button } from 'antd'; function App() { return <Button type="primary">按钮</Button> }