title: ComponentDidMount Code Executing even after component unmounts
body: <p>Inside ComponentDidMount() we call an api periodically to get data. But the api is still getting called even after the component unmounts.</p>
  
  <pre><code>async componentDidMount() {
      let { getItemHistoryData } = this.props;
  
      for (let i = 0; i &lt; 25 &amp;&amp; !this.props.is_synched; i++) {
          await wait(5000);
          getItemHistoryData();
      }
  }
  
  
  const wait = (ms) =&gt; {
      return new Promise(resolve =&gt; setTimeout(resolve, ms));
  }
  </code></pre>
  
  <p>But even if the user moves to a different page, getItemHistoryData() action is getting called.</p>