Skip to content
Advertisement

Stop game loop on conditional with React

I am unable to stop the loop after a conditional. I am able to stop the interval after a button click but unable to stop it after a conditional such as loop increments. This simple example tries to stop the interval loop after 5 loops.

Any solutions would be much appreciated!

JavaScript

Advertisement

Answer

The solution is to put the conditional at the component level, not in the loop method.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement