title: change state with conditionals inside a UseEffect (simple counter with hooks)
body: <p>I'm trying to build a simple percentage counter from 0 to 100 that is updating itself using SetInterval() inside useEffect(). I can get the counter work but I would like to restart the counter once it reaches the 100%. This is my code:</p>
  
  <pre><code>const [percentage, setPercentage]=useState(0);
  
      useEffect(() =&gt; {
  
  const intervalId= setInterval(() =&gt; {
  
              let per = percentage=&gt; percentage+1
  
              if(per&gt;=100){
                  per=0
              }
  
  
  
           setPercentage(per)
  
  
  
  
  
          }, 100);
  
  
  
          return () =&gt; {
  
          }
      }, [])
  
  </code></pre>
  
  <p>Inside the console I can see the state is increasing but it will ignore the if statement to reset the state to 0 once it reaches 100. How can I tackle this knowing that if conditionals are not great with hooks setState?</p>