Skip to content

Commit

Permalink
fix state not correct sync
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed May 9, 2018
1 parent e4e21a6 commit b6f98e3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ function componentWillMount() {

function componentWillReceiveProps(nextProps) {
// Call this.constructor.gDSFP to support sub-classes.
var state = this.constructor.getDerivedStateFromProps(nextProps, this.state);
if (state !== null && state !== undefined) {
this.setState(state);
}
this.setState(function updater(prevState) {
return this.constructor.getDerivedStateFromProps(nextProps, prevState) || {};
});
}

function componentWillUpdate(nextProps, nextState) {
Expand Down

0 comments on commit b6f98e3

Please sign in to comment.