reactjs / react-timer-mixin

TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Receiving a warning from TimerMixin after unmounting the component.

bcowgill opened this issue · comments

Appears not to work properly, perhaps because used as a @mixin() ?

Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the undefined component.
warning @ warning.js?8a56:44
getInternalInstanceReadyForUpdate @ ReactUpdateQueue.js?fd2c:45
ReactUpdateQueue.enqueueSetState @ ReactUpdateQueue.js?fd2c:192
ReactComponent.setState @ ReactComponent.js?702a:67
_handleDismiss @ AlertBanner.js?c408:195
(anonymous function) @ TimerMixin.js?fbdb:18
.

import { mixin } from 'core-decorators'
import TimerMixin from 'react-timer-mixin'

@mixin(TimerMixin)
class AlertBanner {
render () {
this._setupDismissTimer()
...
}
_setupDismissTimer () {
let theTimer = this._dismissTimer
if (this.state.autoDismiss
&& this._isShowing(this.state.transition)) {
if (!theTimer) {
theTimer = this.setTimeout(
this._handleDismiss
, TIMEOUT)
}
}
else {
this._clearDismissTimer()
}
this._dismissTimer = theTimer
}
@autoBind
_handleMouseEnter () {
this._clearDismissTimer()
}
@autoBind
_handleMouseLeave () {
this._setupDismissTimer()
}
_clearDismissTimer () {
const timer = this._dismissTimer
this._dismissTimer = void 0
if (timer) {
this.clearTimeout(timer)
}
}
}

I have to add this method to prevent an error, but I thought that was the point of this mixin to not have to clear any timers before we unmount.

componentWillUnmount() {
    this._clearDismissTimer()
}