I have a problem with context, context api return to me undefined value.
Here is my code :
import { createContext } from "react";
const authContext = createContext();
export default authContext;
authContext.js
import React, { useReducer } from "react";
import authContext from "./authContext";
import authReducer from "./authReducer";
const authState = () => {
const initState = {
authValidte: false,
authToken: null,
authId: null,
};
const [state, dispatch] = useReducer(authReducer, initState);
return (
<authContext.Provider
value={{
authValidte: state.authValidte,
authToken: state.authToken,
authId: state.authId,
}}
>
{props.children}
</authContext.Provider>
);
};
export default authState;
authState.js
Component who want to use context :
...
import authContext from "./context/auth/authContext";
function App() {
const AuthContext = useContext(authContext);
console.log(AuthContext); // undefined
...