I have two functions in react. One is a recursive function which will repeatedly call itself after finishing the main operations based on whether a flag variable is true or false.
I have a button which calls a toggle function to switch the flag variable between true and false.
If it is false i want to stop the recursion and when i click the button again, the variable will switch to true and runs the recursuve function.
The problem i have is the variable is updated within the toggle function but not in the recursive function therefore the recursive function cant be stopped.
I have tried many ways including usestate for the flag variable, set timeout and clear interval also didnt work (recursive function kept on running). Please help me out, let me know if you need the specific code
Via Active questions tagged javascript - Stack Overflow https://ift.tt/Jk789W3
Comments
Post a Comment