Skip to content

Commit

Permalink
Added user context
Browse files Browse the repository at this point in the history
  • Loading branch information
harikrishnan-git committed Jan 22, 2025
1 parent ecbcbe6 commit 0f36715
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions frontend/src/Context/AuthContext.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Children, createContext, useContext, useState } from "react";

export const authContext = createContext();

export const useAuthContext = () => {
return useContext(AuthContext);
};

export const AuthContextProvider = ({ children }) => {
const [authUser, setAuthUser] = useState(
JSON.parse(localStorage.getItem("chat-user") || null)
);

return (
<AuthContext.Provider value={{ authUser, setAuthUser }}>
{children}
</AuthContext.Provider>
);
};
5 changes: 4 additions & 1 deletion frontend/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { createRoot } from "react-dom/client";
import "./index.css";
import App from "./App.jsx";
import { BrowserRouter } from "react-router-dom";
import { AuthContextProvider } from "./Context/AuthContext.jsx";

createRoot(document.getElementById("root")).render(
<StrictMode>
<BrowserRouter>
<App />
<AuthContextProvider>
<App />
</AuthContextProvider>
</BrowserRouter>
</StrictMode>
);

0 comments on commit 0f36715

Please sign in to comment.