From 25ed91477d9d3858666350bca0fba9d9b842c5e9 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 24 Nov 2022 00:04:28 +0200 Subject: [PATCH] fix funky rendering when logged in from a previous session --- src/App.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/App.js b/src/App.js index 6ac0548..e6d99bc 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import { BrowserRouter, Navigate, Route, Routes} from 'react-router-dom'; import './css/App.css'; @@ -16,34 +16,41 @@ import Admin from './pages/Admin'; function App() { - const [user] = useLoginContext(); + const [user, updateUser] = useLoginContext(); + const [loading, setLoading] = useState(true); useEffect(() => { - fetchUser(); + (async () => { + await fetchUser(); + updateUser(); + setLoading(false); + })(); }, []); const menuItems = [ { to: '/home', label: 'Home' }, { to: '/users', label: 'Users' }, { to: '/admin', label: 'Admin' } + ]; -]; + if (loading) return null; return (
-
- -
-
{user ? - - - +
+
+ +
+ + + +
: null}