现在我有类似的组件:
class MyComponent extends Component {
componentWillMount() {
dispatch(requestReservation(params.orderCode))
}
...
我的目标是从该组件到HOC分别进行数据分发和等待,
类似:
export const withData = WrapedComponent => {
return class extends Component {
componentDidMount() {
this.props.askData(this.props)
}
render() {
return this.props.dataIsReady ? <WrapedComponent {...this.props} /> : null
}
}
}
export default withData
并使用它:
export const MyCompentConnect = connect(state, props) => {
...
askData: ({ dispatch , params}) => {
dispatch(selectData(params))
},
isDataReady: isUndefined(state.flight)
)(withData(MyComponent))