我的以下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)} />

最佳答案

您不能用checkPermissions包装connect,因为它也是HOC。
相反,您必须组成它们。

import { compose } from 'redux';

...
export default compose(
  connect(state=>state.global, {fetchUsers}),
  CheckPermission
);

07-26 00:16