const [currentUser, setCurrentUser] = useState(undefined)
useEffect(() => {
async function fetchdata() {
const storedUser = localStorage.getItem("chat-app-user");
if (!storedUser) {
navigate("/login");
} else {
const user = await JSON.parse(storedUser);
console.log("Fetched user from localStorage:", user);
setCurrentUser(user);
}
}
fetchdata();
}, [navigate]);
I am trying to setCurrentUser. I am getting an user from local storage but while setting it to setCurrentUser it is not getting set and currentUser is remaining undefined