diff --git a/src/AuthenticatedApp.js b/src/AuthenticatedApp.js index 0731cca..0826f86 100644 --- a/src/AuthenticatedApp.js +++ b/src/AuthenticatedApp.js @@ -18,7 +18,6 @@ import { useUser } from './context/user'; function AuthenticatedApp() { const { state } = useUser(); - const { pathname } = useLocation(); const layoutType = useLayoutType(); return ( @@ -35,7 +34,10 @@ function AuthenticatedApp() { maxWidth="false" sx={layoutType === 'desktop' ? container : mobileContainer} > - + } /> } /> diff --git a/src/context/user.js b/src/context/user.js index df2a4fd..f6b9bc3 100644 --- a/src/context/user.js +++ b/src/context/user.js @@ -1,4 +1,5 @@ import { createContext, useContext, useEffect, useState } from 'react'; +import { useLocation } from 'react-router-dom'; import { sleep } from '../utils/sleep'; import { useAuthState } from './auth'; @@ -40,16 +41,18 @@ const UserContext = createContext(); function UserProvider(props) { const { user } = useAuthState(); + const { pathname } = useLocation(); const [state, setState] = useState({ status: 'idle', user: null, classrooms: [], error: null, + pathname: '', }); useEffect(() => { - setState({ user }); - }, [user]); + setState({ user, pathname }); + }, [user, pathname]); const classrooms = () => { setState({ ...state, status: 'pending' });