score:1

Accepted answer
useEffect(() => {
  const listener = this.props.firebase.auth.onAuthStateChanged(
    authUserResponse => {
      setAuthUser(authUserResponse || null);
    }
  );
  return listener; // run listener function when component unmounts
}, []);

score:0

const withAuthentication = (Component) => {

const WithAuthentication = (props) => {
    
    const [authUser, setAuthUser] = useState(null);
 
    useEffect(() => {
     props.firebase.auth.onAuthStateChanged(
        authUser => {
          authUser
            ? setAuthUser(authUser)
            : setAuthUser(null);
        })
    }, [authUser]);
  
    return (
    <AuthUserContext.Provider value={authUser}>
        <Component {...this.props} />
    </AuthUserContext.Provider>
    );
  }
 
  return withFirebase(WithAuthentication);
};

Related Query

More Query from same tag