【发布时间】:2018-09-17 22:57:40
【问题描述】:
下面我的 HOC 有什么问题?出现无法将类调用为函数的错误?
https://i.imgur.com/SirwcGZ.png
我的 HOC
const CheckPermission = (Component) => {
return class App extends Component {
componentDidMount() {
this.props.fetchUsers().then(resp => {
this.setState({user: true, loading: false});
})
}
render() {
const { user, loading } = this.props
loading && <div>Loading...</div>
!user && <Redirect to="/dashboard" />
return <Component {...this.props} />
}
}
}
export default connect(state=>state.global, {fetchUsers})(CheckPermission)
这就是我导入和使用 CheckPermission 的方式:
<Route exact path='/dashboard' component={CheckPermission(Dashboard)} />
【问题讨论】:
标签: javascript reactjs ecmascript-6 redux