-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Warning message no longer recommends using deprecated lifecycle method. #12760
Conversation
I'd prefer a warning that's a bit more detailed. "Either assign the initial state in constructor, or move the setState call to componentDidMount." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
@gaearon I have updated the warning message. please take a lot. |
Please run |
@@ -425,10 +425,9 @@ describe('ReactCompositeComponent', () => { | |||
expect(() => { | |||
instance = ReactDOM.render(<Component />, container); | |||
}).toWarnDev( | |||
'Cannot update during an existing state transition (such as within ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add "(such as within render...)" part back? I don't see why it needs to be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was just thinking it was lengthy.
maybe perhaps instead of printing "Cannot update during an existing state transition" , It is better to be concise and print "Cannot update state during render lifecycle method" ?
Looking at this again, I don't see why the message assumes we're in the constructor. This code is for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaearon why the message assumes we are in the constructor? right now it suggests to initially set the state in the constructor, or use setState on componentDidMount
, instead of using setState in render
(so it assumes we are in render
method)
@@ -425,10 +425,9 @@ describe('ReactCompositeComponent', () => { | |||
expect(() => { | |||
instance = ReactDOM.render(<Component />, container); | |||
}).toWarnDev( | |||
'Cannot update during an existing state transition (such as within ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was just thinking it was lengthy.
maybe perhaps instead of printing "Cannot update during an existing state transition" , It is better to be concise and print "Cannot update state during render lifecycle method" ?
I can't really understand why CircleCi is failing on Test Suites: 149 passed, 149 total |
@iliran11 you need to run |
Hi Liran Cohen(@iliran11), @gaearon Sorry again if it creates notification noise on the repository. |
Sorry for the churn. I ended up merging #13169 because it was more accurate: as it turned out, this code path doesn't actually run for the constructor anymore. So mentioning constructor didn't make sense. Thanks for the effort though! |
Fixing the folllwing issue: #12748;
componentWillMount
is soon to be deprecated method, so recommending to use it, is not a viable options.Author of the warning message has warned against constructor side-effects. as per the official react docs, the right way to do it, is placing those side effects in
componentDidMount
.