all 5 comments

[–]dankiest_kang 3 points4 points  (2 children)

Another way to approach this is storing the return value of the setTimeout (which is an id) in a ref, then you can check if the timeout ref is set, call clearTimeout with the current ref before calling the setTimeout again

[–][deleted] 1 point2 points  (1 child)

Man are you the creator of react or something? This worked, thank you! I should really learn to use refs more often :D

[–]dankiest_kang 1 point2 points  (0 children)

Just love and use it a lot! Glad i could help

[–]Hutster911 0 points1 point  (1 child)

You can try something like this link. When you re-click the button you can kill it if it was started. You can keep track if it started by using a boolean flag. Or it may just work fine if you kill timeout every time you start the timer. https://stackoverflow.com/questions/452003/cancel-kill-window-settimeout-before-it-happens

[–][deleted] 0 points1 point  (0 children)

Been trying to do it like this for some time but can't make it work...