fix: fix context API issue

-wrap the entire app with context provider component
-pass the context with the provider value
This commit is contained in:
sushant dhimal 2023-03-14 23:40:12 +05:45
parent c947e488cc
commit b9394e0e4d
2 changed files with 8 additions and 5 deletions

View File

@ -17,8 +17,8 @@ export const AuthContextProvider = ({ children }) => {
}, [state.currentUser]);
return (
<AuthContextProvider value={{ currentUser: state.currentUser, dispatch }}>
<AuthContext.Provider value={{ currentUser: state.currentUser, dispatch }}>
{children}
</AuthContextProvider>
</AuthContext.Provider>
);
};

View File

@ -4,13 +4,16 @@ import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { BrowserRouter } from "react-router-dom";
import { AuthContextProvider } from "./context/AuthContext";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
<AuthContextProvider>
<BrowserRouter>
<App />
</BrowserRouter>
</AuthContextProvider>
</React.StrictMode>
);