Skip to content

Commit

Permalink
this.setState() will only call when the component is mounted. (in alt…
Browse files Browse the repository at this point in the history
…SetState())
  • Loading branch information
senxation committed Nov 1, 2017
1 parent fdaec5c commit d476120
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/AltContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ class AltContainer extends React.Component {
}

componentDidMount() {
this._isMounted = true;
if (this.props.onMount) this.props.onMount(this.props, this.context)
}

componentWillUnmount() {
this._isMounted = null;
this._destroySubscriptions()
if (this.props.onWillUnmount) {
this.props.onWillUnmount(this.props, this.context)
Expand Down Expand Up @@ -194,7 +196,9 @@ class AltContainer extends React.Component {
}

altSetState = () => {
this.setState(reduceState(this.props))
if (this._isMounted) {
this.setState(reduceState(this.props))
}
}

getProps() {
Expand Down

0 comments on commit d476120

Please sign in to comment.