'Problem with onAuthStateChanged (React & Firebase)
I'm using firebase and i want to solve problem with delay. When I'm refreshing currentUser is setting to null and my component is not showing but after 2 sec it is working correctly. Here is code:
Code example:
type FirebaseUserState = User | null;
export function useAuth() {
let [currentUser, setUser] = useState<FirebaseUserState>(null);
auth.onAuthStateChanged((user) => {
if (user !== null) {
setUser(user);
}
});
return currentUser;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
