Reputation: 59
Does this clear my timeout
const timer1 = setTimeout(()=> {
setSuccessMessage('')
clearTimeout(timer1)
},3000);
The code execute well, but I need to know if the timer is cleared at the end. I've tested a solution given in this post but the timer get cleared before my stuff get finished, and considering that my timeout is intended to hide a message, the former remains displayed because the timer got cleared.
Upvotes: 1
Views: 1630
Reputation: 2923
You do not need to cancel your timer here as it is automatically garbage collected after it is executed.
You do need to cancel it only if you ever intend to cancel it BEFORE it is fired, which is not your case.
Upvotes: 4