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 (