I have this react App structure. Some components are hidden based on the content of a local storage.
import React from "react";
import { BrowserRouter as Router } from "react-router-dom";
import AppRoutes from "./Routes";
import NavBar from "./components/NavBar";
const App = () => {
return (
<Router>
<NavBar />
<AppRoutes />
</Router>
);
};
export default App;
All of my other react components are responsive except Navbar. What am I doing wrong? This is my NavBar code:
import { useEffect, useState } from "react";
function NavBar() {
const [role, setRole] = useState("");
useEffect(() => {
setRole(localStorage.getItem("tempUserRole"));
}, []);
return (
<header className="bg-white">
<nav className="" aria-label="Global">
{/* Links (Center-aligned) */}
<div className="">
{role==='a' && <a href="/events" className="">a</a>}
{role==='b' && <a href="/events" className="">EveBnts</a>}
</div>
</nav>
</header>
);
}
export default NavBar;
The problem is, I have to refresh the page to see the changes take effect. How do I solve this issue?