Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Receiving a warning from TimerMixin after unmounting the component. #14

@bcowgill

Description

@bcowgill

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()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions