Reputation: 17
when i have my functions in UserAuthContext.js my App isn't working properly. I try to login but the user is not directet to /browse as it should. But if i put the same code in app.js i can create and login with an account. I don't know what the reason is here is the code https://codesandbox.io/s/cool-euler-eicfr?file=/src/App.js -not working version (above code belongs to this): https://not-working.netlify.app/ -working version where i have the code in app.js https://netflix-clone-kasamtde.netlify.app/
Upvotes: 0
Views: 87
Reputation: 1466
You cannot use useAuthContext
in a component that is not a child of UserAuthContextProvider
. It will always return undefined
Easiest fix for this is to move UserAuthContextProvider
into index.js
:
// index.js
import React from 'react';
import {render} from 'react-dom';
import './index.css';
import App from './App';
import UserAuthContextProvider from "./components/Contexts/UserAuthContext.js";
render(
<React.StrictMode>
<UserAuthContextProvider><App /></UserAuthContextProvider>
</React.StrictMode>,
document.getElementById('root')
);
Upvotes: 1