Closed codequistador closed 3 years ago
I should have read @timvanmourik's PR before posting this. I think it is sorted with his approach.
const [authUser, setAuthUser] = useState(
JSON.parse(localStorage.getItem('authUser') as string)
)
useEffect(() => {
const unsubscribe = props.firebase.auth.onAuthStateChanged(
(authUser: any) => {
localStorage.setItem('authUser', JSON.stringify(authUser))
setAuthUser(authUser)
},
() => {
localStorage.removeItem('authUser')
setAuthUser(null)
}
)
return () => unsubscribe()
})
First of all, thank you for this excellent tutorial. I have a full-cycle auth app up and running and it was fun and easy to do!
Second, I am using the hooks api for most of the meat of my app (still using
withFirebase
as a HOC)... in the step where we save theauthUser
state toApp
you added acomponentWillUnmount
to reset the listener. I got lost at this step... here is my implementation:Is there potential for memory leakage here?
Thanks again!
Justin