小编Toh*_*awk的帖子

asynchronous context with useEffect in React

im trying to create an api request with the header value, that is received from a context component. However, as soon as the page component is loaded, it throws an Cannot read property '_id' of null exception. Is there a way to run the useEffect function, as soon as the context is loaded?

main component:

import React, { useState, useEffect, useContext } from "react";
import "./overview.scss";

/* COMPONENTS */;
import axios from 'axios';
import { GlobalContext } from '../../components/context/global';

const …
Run Code Online (Sandbox Code Playgroud)

asynchronous reactjs react-context react-hooks use-effect

4
推荐指数
1
解决办法
4553
查看次数