Updates the warning that is displayed when `setState` is called within either `render` or a component constructor.
Updates the warning that is displayed when `setState` is called within either `render` or a component constructor. Follow up to #5343
Andrew Clark committed
Nov 5, 2015 at 11:12 UTC
5fec308d60aef39d44ea6c077116abd0fe51aed4
2 files changed
+9
-5
src/renderers/shared/reconciler/ReactUpdateQueue.js
+5
-3
@@ -47,9 +47,11 @@ function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
47
if (__DEV__) {
48
warning(
49
ReactCurrentOwner.current == null,
50
- '%s(...): Cannot update during an existing state transition ' +
51
- '(such as within `render`). Render methods should be a pure function ' +
52
- 'of props and state.',
50
+ '%s(...): Cannot update during an existing state transition (such as ' +
51
+ 'within `render` or another component\'s constructor). Render methods ' +
52
+ 'should be a pure function of props and state; constructor ' +
53
+ 'side-effects are an anti-pattern, but can be moved to ' +
54
+ '`componentWillMount`.',
55
callerName
56
);
57
}
src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js
+4
-2
@@ -381,8 +381,10 @@ describe('ReactCompositeComponent', function() {
381
expect(console.error.calls.length).toBe(1);
382
expect(console.error.argsForCall[0][0]).toBe(
383
'Warning: setState(...): Cannot update during an existing state ' +
384
- 'transition (such as within `render`). Render methods should be a pure ' +
385
- 'function of props and state.'
384
+ 'transition (such as within `render` or another component\'s ' +
385
+ 'constructor). Render methods should be a pure function of props and ' +
386
+ 'state; constructor side-effects are an anti-pattern, but can be moved ' +
387
+ 'to `componentWillMount`.'
388
);
389
390
// The setState call is queued and then executed as a second pass. This