A
A
antonini6662020-06-20 13:07:55
React
antonini666, 2020-06-20 13:07:55

How to use useEffect instead of componentDidMount and componentWillUnmount?

Hello, how to rewrite such code on useEffect? Thanks in advance

state = {
      authUser: null,
};

componentDidMount() {
    this.listener = this.props.firebase.auth.onAuthStateChanged(
      authUser => {
        authUser
          ? this.setState({ authUser })
          : this.setState({ authUser: null });
      },
    );
  }
 
  componentWillUnmount() {
    this.listener();
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question