react sleep 1 second code example
Example 1: sleep in react
sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
componentDidUpdate(prevProps, prevState, snapshot) {
this.sleep(5000).then(r => {
})
}
Example 2: wait javascript
wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Example 3: javascript sleep function
sleep = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));
sayHi = async () => {
await sleep(1000);
console.log('Hi');
}