title: Why is the "webpage is slowing down" occuring on using a while loop with a setTimeout in React?
body: <p>I made this component in React with a while loop which has a  setTimeout inside it. It is causing the browser to stop responding and I get "webpage is slowing down" in Firefox developers browser and in chrome too. What is the possible reason? Here is the code:-</p>
  
  <pre><code>class Adbanner extends React.Component{
  
  changer() {
  
          var i=0;  
          while(i&gt;=0 &amp;&amp; i&lt;4){ 
            setTimeout(function(){
               document.getElementById('ad').src=adarray[i];
               i++; 
            }, 2000);            
  
          }     
  }
  
      render() {
      return (
         &lt;div&gt;
              &lt;input id="ad" type="image" src={ad2} style={{position:'absolute',height:'50%',width:'100%'}}&gt;&lt;/input&gt;      
            {setInterval(this.changer, 2000)}  
         &lt;/div&gt;
      );
    }
  }
  
  export default Adbanner;
  </code></pre>
  
  <p>How to solve it?</p>