Search code examples
reactjsreact-hooksreact-context

Problem in useContext on react js when I practise Codesandbox! Please


Here the link https://codesandbox.io/s/usecontex-tha-ewwepl I found the error in the child component. Please help.


Solution

  • You should wrap your main application in the provider you have written. A ton of information can be found at the react docs

    import "./styles.css";
    import Child from "./Child";
    import { AppProvider } from "./UserContext";
    export default function App() {
      return (
        <div className="App">
          <AppProvider>
            <Child />
          </AppProvider>
        </div>
      );
    }