Skip to content

setState called after component has unmounted #7

@dchartfield

Description

@dchartfield

I came across the following Warning in my app

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 StatefulDashboard component.

and on farther inspection it appears my Dashboard component, which had already unmounted was connected to a store that had been modified. The connectToStores#onChange was called, which in turn called this.setState(...), resulting in the above Warning message.

I'm thinking an isMounted() check would be applicable in the onChange method:

      onChange: function onChange() {
        if ( this.isMounted() ) {
          this.setState(Spec.getPropsFromStores(this.props, this.context));
        }
      },

Updating like so resolves the issue on my end. Let me know if you agree, and I can create a PR

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