I was learning some new concepts and had a question that I couldn't find an answer to online.
So, here's the button I have:
<button onClick={toggle} className="common-btn">{buttonText}</button>
I want this button to control the duration of a section of code being executed. In the toggle method, I update the state successfully. However, when I tried using a while loop to break out of the code execution like this:
...
setRunning(!running)
if(running){
while(running)
{
console.log("Running")
}
}
...
The problem is that it never breaks out of the while loop. Even if the state is false, the original while loop continues to run. Does anyone have any insights on how to approach this differently?