0,_hoc.default不是函数允许循环,但可能会导致未初始化的值

问题描述

这是我的错误,去创建一个HOC use函数组件而不是类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

有人想解决这个问题吗?非常感谢!

解决方法

我已经解决了这个问题! 感谢@lissettdm和@Viet Dinh。 这是我使用RequiredAuth错误方式去的问题。