Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Guard setState so that it is not called when the container is already unmounted #36

Merged

Conversation

leonid-shevtsov
Copy link
Contributor

This is done to silence a warning in React:

Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component CalculatorContainer. This is a no-op.

See discussion at facebook/react#2787

As this issue is unresolved and there is no final opinion from React devs, I think it's prudent to add a guard for the time being.

@RickWong
Copy link
Owner

RickWong commented Aug 4, 2015

Haven't followed the official discussion. Is the "Note" about ES6 classes on https://facebook.github.io/react/docs/component-api.html#ismounted not relevant anymore? @leonid-shevtsov

@leonid-shevtsov
Copy link
Contributor Author

It is relevant, and when you create an ES6 class that extends React.Component it doesn't have isMounted. But since you are creating the containers with React.createClass, you're fine.

Transmit containers with this patch interop with ES6 classes as usual.

(It's the ES6 classes themselves that, in a similar situation, would have to resort to checking a flag set in componentWillUnmount() or something like that. I hope that in the future the React team will work out a better solution.)

@RickWong RickWong merged commit eba9e48 into RickWong:master Aug 6, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants