title: How can I clear a setTimeout which is created on a component life cycle?
body: <p>The thing is that I am getting this warning: </p>
  
  <blockquote>
    <p>Warning: Can’t call setState (or forceUpdate) 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.</p>
  </blockquote>
  
  <p>And it is because of this:</p>
  
  <pre><code>  componentDidUpdate(props, state) {
      const {
        pushNotificationData,
        unassignedPickUpPassengers,
        unassignedDropOffPassengers,
      } = this.props;
  
      if (props.pushNotificationData !== pushNotificationData) {
        this.applyOpacityForSomeSeconds(0.5, 0);
      }
  
      if (
        props.unassignedPickUpPassengers !== unassignedPickUpPassengers ||
        props.unassignedDropOffPassengers !== unassignedDropOffPassengers
      ) {
        this.applyOpacityForSomeSeconds(1, 1000);
      }
    }
  
    applyOpacityForSomeSeconds = (setOpacity, timeout) =&gt;
      setTimeout(() =&gt; {
        this.setState({ lastIndexOpacity: setOpacity });
      }, timeout);
  </code></pre>
  
  <p>How should I clear the timeout on a componentWillUnmount? Is that the proper way of doing this or is there any other way?</p>