fix: rerender header on user login
All checks were successful
Build and Deploy Go App / build (push) Successful in 11m18s
Build and Deploy Go App / deploy (push) Successful in 30s

This commit is contained in:
nihonium 2025-12-19 22:52:49 +03:00
parent 9affe90988
commit 490443b63f
Signed by: nihonium
GPG key ID: 0251623741027CFC
2 changed files with 11 additions and 1 deletions

View file

@ -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 () => {