Skip to content

Commit

Permalink
Handlers should not call setState() after being unmounted (related to #…
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Feb 14, 2016
1 parent 1e6f3e3 commit 237ba41
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/decorateHandler.js
Expand Up @@ -68,6 +68,10 @@ export default function decorateHandler({
this.state = this.getCurrentState();
}

componentDidMount() {
this.isCurrentlyMounted = true;
}

componentWillReceiveProps(nextProps) {
if (!arePropsEqual(nextProps, this.props)) {
this.receiveProps(nextProps);
Expand All @@ -77,6 +81,7 @@ export default function decorateHandler({

componentWillUnmount() {
this.disposable.dispose();
this.isCurrentlyMounted = false;
}

receiveProps(props) {
Expand Down Expand Up @@ -126,6 +131,10 @@ export default function decorateHandler({
}

handleChange() {
if (!this.isCurrentlyMounted) {
return;
}

const nextState = this.getCurrentState();
if (!shallowEqual(nextState, this.state)) {
this.setState(nextState);
Expand Down

0 comments on commit 237ba41

Please sign in to comment.