Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix state not correct sync #24

Merged
merged 1 commit into from
May 9, 2018
Merged

Conversation

zombieJ
Copy link
Contributor

@zombieJ zombieJ commented May 9, 2018

Current getDerivedStateFromProps get state ood when setState is called which is not same behavior as React 16.3

var state = this.constructor.getDerivedStateFromProps(nextProps, this.state);

Sample: https://codesandbox.io/s/nw3k9kqk00


PS: But in old version of react, this change will cause re-render when user return null.

@bvaughn bvaughn self-assigned this May 9, 2018
@bvaughn
Copy link
Contributor

bvaughn commented May 9, 2018

Ah, nice catch!

@bvaughn bvaughn merged commit b6f98e3 into reactjs:master May 9, 2018
@bvaughn
Copy link
Contributor

bvaughn commented May 9, 2018

I added a test (45c32b7) that failed before this fix to guard against a regression.

@bvaughn
Copy link
Contributor

bvaughn commented May 9, 2018

Just published v3.0.3 with this fix. Thanks for the PR! 😄

@Hypnosphi
Copy link
Contributor

Hypnosphi commented May 11, 2018

This throws with react-test-renderer because it doesn't pass this to updater function https://github.com/facebook/react/blob/master/packages/react-test-renderer/src/ReactShallowRenderer.js#L301

The fix would be just to use arrow function, I'll submit a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants