fix: rerender header on user login
This commit is contained in:
parent
9affe90988
commit
490443b63f
2 changed files with 11 additions and 1 deletions
|
|
@ -14,8 +14,16 @@ export const Header: React.FC = () => {
|
|||
// Listen for localStorage changes to update username dynamically
|
||||
useEffect(() => {
|
||||
const handleStorage = () => setUsername(localStorage.getItem("user_name"));
|
||||
// This catches changes from OTHER tabs
|
||||
window.addEventListener("storage", handleStorage);
|
||||
return () => window.removeEventListener("storage", handleStorage);
|
||||
|
||||
// This catches changes in the CURRENT tab if you use dispatchEvent
|
||||
window.addEventListener("local-storage-update", handleStorage);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("storage", handleStorage);
|
||||
window.removeEventListener("local-storage-update", handleStorage);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleLogout = async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue