-
使用
HOC
对react
的class组件
进行装饰 -
装饰器分为两个:
page
&component
,page
装饰器可以设置页面title
,其他功能如下 -
引入
style
样式 -
设置
form: true
后,自动将组件用antd from
包裹,可在props
中拿到form
的方法, 也可以在HOC
中封装更多方法Form.create({ name: 'wrapped_form_component' })(WrappedComponent);
-
可以把组件初始时的请求从生命周期中转移到
preload
中,结果直接挂载到props
上 -
如果用到
redux
,则设置connect
,将mapStateToProps
mapDispatchToProps
挂载到props
上 -
更多基于
antd
的UI
组件封装...
@hoc({
form: true,
style: require('./style.scss'),
// 页面初始化时预加载一些请求,结果挂载到props上
preload: (props) => ({
preloadData: getNumber(props),
}),
connect: {},
})
class Demo extends Component {
constructor(props) {
super(props);
}
render() {
const { preloadData } = this.props;
return (
<div>
<input type="text" className="text" />
<div>{preloadData}</div>
</div>
);
}
}
- 重写
webpack
配置,丰富功能。 css
的HotModuleReplacement
未生效,原因不明😳