mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Updates the warning that is displayed when setState is called
within either `render` or a component constructor. Follow up to #5343
This commit is contained in:
@@ -47,9 +47,11 @@ function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
|
||||
if (__DEV__) {
|
||||
warning(
|
||||
ReactCurrentOwner.current == null,
|
||||
'%s(...): Cannot update during an existing state transition ' +
|
||||
'(such as within `render`). Render methods should be a pure function ' +
|
||||
'of props and state.',
|
||||
'%s(...): Cannot update during an existing state transition (such as ' +
|
||||
'within `render` or another component\'s constructor). Render methods ' +
|
||||
'should be a pure function of props and state; constructor ' +
|
||||
'side-effects are an anti-pattern, but can be moved to ' +
|
||||
'`componentWillMount`.',
|
||||
callerName
|
||||
);
|
||||
}
|
||||
|
||||
@@ -381,8 +381,10 @@ describe('ReactCompositeComponent', function() {
|
||||
expect(console.error.calls.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toBe(
|
||||
'Warning: setState(...): Cannot update during an existing state ' +
|
||||
'transition (such as within `render`). Render methods should be a pure ' +
|
||||
'function of props and state.'
|
||||
'transition (such as within `render` or another component\'s ' +
|
||||
'constructor). Render methods should be a pure function of props and ' +
|
||||
'state; constructor side-effects are an anti-pattern, but can be moved ' +
|
||||
'to `componentWillMount`.'
|
||||
);
|
||||
|
||||
// The setState call is queued and then executed as a second pass. This
|
||||
|
||||
Reference in New Issue
Block a user