title: Cancelling tasks in the componentWillUnmount
body: <p>This is a common problem, yet I know why and can generally fix quickly.</p>
  
  <p>However, on this occasion, I cannot seem to unmount the tasks in my ReactJS and GatsbyJS application.</p>
  
  <p>The code below is listening to Firebase <code>auth</code> changes and the with <code>setState</code> is making the <code>auth</code> users details available within <code>state</code></p>
  
  <pre><code>_initFirebase = false;
  
  constructor(props) {
    super(props);
  
    this.state = {
      authUser: null
    };
  }
  
  firebaseInit = () =&gt; {
    const { firebase } = this.props;
    if (firebase &amp;&amp; !this._initFirebase) {
      this._initFirebase = true;
  
      this.listener = firebase.onAuthUserListener(
        authUser =&gt; {
          localStorage.setItem('authUser', JSON.stringify(authUser));
          this.setState({ authUser });
        },
        () =&gt; {
          localStorage.removeItem('authUser');
          this.setState({ authUser: null });
        }
      );
    }
  };
  
  componentDidMount() {
    this.setState({
      authUser: JSON.parse(localStorage.getItem('authUser'))
    });
  
    this.firebaseInit();
  }
  
  componentDidUpdate() {
    this.firebaseInit();
  }
  
  componentWillUnmount() {
    this.listener &amp;&amp; this.listener();
  }
  </code></pre>
  
  <p>Causing an error in the console of</p>
  
  <pre><code>Warning: Can't perform a React state update on an unmounted component. 
  
  This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
      in WithAuthentication (created by Context.Consumer)
      in Component (created by Layout)
      in Layout (created by SigninPage)
      in SigninPage (created by HotExportedSigninPage)
      in AppContainer (created by HotExportedSigninPage)
      in HotExportedSigninPage (created by PageRenderer)
  </code></pre>
  
  <p>From my understanding, I have sufficiently <code>unmount</code> these <code>setState</code> tasks within <code>componentWillUnmount</code>.</p>
  
  <p>Could you please explain what I may have missed?</p>