From ab6252e67a51936c010b65f81a7aa9afb6682a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Mur=C3=A7a?= Date: Wed, 15 Jun 2022 14:36:14 -0300 Subject: [PATCH] Move up pathname to useUser --- src/AuthenticatedApp.js | 6 ++++-- src/context/user.js | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) 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' });