这是我的错误去创建一个 HOC 使用函数组件而不是类 Component
Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
[Fri Oct 16 2020 24:17:29.696] ERROR TypeError: (0, _hoc.default) is not a function. (In '(0, _hoc.default)(BankingOnline)', '(0, _hoc.default)' is undefined)
[Fri Oct 16 2020 24:17:29.696] ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
[Fri Oct 16 2020 24:17:29.696] ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
[Fri Oct 16 2020 24:17:29.697] ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
我的代码:
import React, { useState, useContext, useEffect } from "react";
import HeaderComponent from '../../components/header';
import { StoreContext } from '../../store';
import NotAuthView from '../../components/notAuth-view'
const RequiredAuth = (Component) => props => {
const { authFlag } = useContext(StoreContext)
if (!authFlag) {
return <NotAuthView />
}
return <Component {...props} />
}
export default RequiredAuth
有人有解决这个问题的想法吗?非常感谢!