Closed
Description
Following line will cause memory leaks when component unmounts before completing the counter lifecycle.
This should be handled in the following way.
componentWillUnmount () {
this.rafHandle && raf.cancel(this.rafHandle)
}
incrementCounter (counter?: number = 0) {
const { to, duration, strict } = this.props
if (this.state.count < to) {
this.setState(({ count: number }): ({ count: number }) => ({
count: this.easeFn(counter, 0, to, duration)
}), () => {
const timeBeforeRag: number = getCurrentTime()
this.rafHandle = raf(() : void => {
const timeAtInc: number = getCurrentTime()
this.incrementCounter(counter + (strict ? timeAtInc - timeBeforeRag : 16))
})
})
}
}