Can anyone please explain how react useEffect hook is working as ComponentWillUnmount here. Also how the loading state is handled using firebase onAuthStateChanged?
const [loading, setLoading] = useState(false);
useEffect(() => {
const auth = getAuth();
const unsubscribe = onAuthStateChanged(auth, (user) => {
setCurrentUser(user);
setLoading(true);
});
return unsubscribe;
}, []);