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

Enhance get derived state from props state warning - #12670 #13317

Conversation

@flxwu
Copy link

@flxwu flxwu commented Aug 3, 2018

The current warning that getDerivedStateFromProps produces when called with state == null (intentional null or undefined/not declared) is a bit unclear, so this PR adapts this message for the developer to directly recognize that he didn't declare the Component's state before getDerivedStateFromProps.

Resolves: #12670.

The updated message is now:

Component state must be properly initialized when using getDerivedStateFromProps.
@gaearon
Copy link
Member

@gaearon gaearon commented Aug 3, 2018

Thanks. I ended up tweaking the message since people are often confused why we have it.

Loading

@gaearon gaearon force-pushed the bugfix/enhance-getDerivedStateFromProps-state-warning branch from 39f9b26 to 0b54ed3 Aug 3, 2018
@flxwu
Copy link
Author

@flxwu flxwu commented Aug 3, 2018

yeah, right 👍 @gaearon although I don't get why you would intentionally set state to null 😅

Loading

@gaearon gaearon merged commit b179bae into facebook:master Aug 3, 2018
1 check passed
Loading
@flxwu flxwu deleted the bugfix/enhance-getDerivedStateFromProps-state-warning branch Aug 3, 2018
TejasQ pushed a commit to TejasQ/react that referenced this issue Aug 26, 2018
…acebook#13317)

* Enhance warning message for missing state with getDerivedStateFromProps

* Adapt tests

* style fix

* Tweak da message

* Fix test
@gaearon gaearon mentioned this pull request Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants