WebDevSimplified / React-Firebase-Auth

637 stars 439 forks source link

setting user on unsubscribe function in useEffect #19

Open Yasin-97 opened 2 years ago

Yasin-97 commented 2 years ago

I'm kinda struggling to understand this piece of code! The unsubscribe fn is run on unmount of this component (context/authContext.js), so how the user and loading states are set to be used in other functions in this component?

useEffect(() => { const unsubscribe = auth.onAuthStateChanged(user => { setCurrentUser(user) setLoading(false) }) return unsubscribe }, [])