有什么方法可以在React组件之外使用上下文值吗?

时间:2019-12-19 03:09:19

标签: javascript reactjs

CreateContextStore.js

import { RootReducer } from './state/reducers/RootReducer';
import { InitialState } from './state/actions/InitialStates';
export const Store = createContext();
function CreateContextStore(){
 const store = useReducer(RootReducer, InitialState);
}
export default CreateContextStore;

WrapperContext.jsx

import React, { Component } from 'react';
import { Store } from '../App';
import {storeLogInStatus} from '../state/actions/Actions'
const ApiFetch = (Comp) => {

class Api extends Component {
    static contextType =  Store;
    componentDidMount() {

        console.log("valuevalue ", this.context)
    }

    render() {

        return (
            <Comp {...this.props} />
        );
    }
}

return Api;

};
export default ApiFetch;

有什么方法可以在React组件之外使用上下文值吗?或从HOC组件访问上下文,当我的Web应用程序中发生无效会话时,我必须在上下文中调用回调。

0 个答案:

没有答案