Reputation: 1694
I am trying to have my code fire 3 seconds after the button being clicked. I can't manage to do this though. Either it is firing immediately or it fires and doesn't stop.
<Button onClick={setTimeout(() => window.location.reload(false), 4000), clearTimeout()}>Spin</Button>
It has been a long time since I've used setTimeout
in any way, so it's probably a very simple fix.
Apologies if there is a similar question to this, I couldn't find anything that was relating to this enough to help me out.
Upvotes: 1
Views: 105
Reputation: 1
You should add an event handler (method) like an arrow function :
onClick={()=>{setTimeout(() => window.location.reload(false), 4000); clearTimeout()}}
or onClick={someFunction}
function someFunction(){
setTimeout(() => window.location.reload(false), 4000); clearTimeout()
}
Upvotes: 1