$ npm i raf-pause
or
$ yard add raf-pause
Start the timer.
Clean the timer.
import rafPause from 'raf-pause'
const run = rafPause(() => {
// do something
}, 500)
run.start()
const runAndLoop = rafPause(() => {
// do something in loop
runAndLoop.start()
}, 500)
runAndLoop.start()
import rafPause from 'raf-pause'
componentDidMount() {
this.countDown.start()
}
componentWillUnMount() {
this.countDown.clean()
}
countDown = rafPause(() => {
this.setState({
...
}, this.countDown)
}, 1000)
It'll fallback to setTimeout
if browsers don't support requestAnimationFrame