Warning message no longer recommends using deprecated lifecycle method.#12760
Warning message no longer recommends using deprecated lifecycle method.#12760iliran11 wants to merge 5 commits intofacebook:masterfrom
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." |
|
@gaearon I have updated the warning message. please take a lot. |
|
Please run |
| expect(() => { | ||
| instance = ReactDOM.render(<Component />, container); | ||
| }).toWarnDev( | ||
| 'Cannot update during an existing state transition (such as within ' + |
There was a problem hiding this comment.
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.
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 |
iliran11
left a comment
There was a problem hiding this comment.
@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)
| expect(() => { | ||
| instance = ReactDOM.render(<Component />, container); | ||
| }).toWarnDev( | ||
| 'Cannot update during an existing state transition (such as within ' + |
There was a problem hiding this comment.
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;
componentWillMountis 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.