From 5fec308d60aef39d44ea6c077116abd0fe51aed4 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 5 Nov 2015 11:12:58 -0800 Subject: [PATCH] Updates the warning that is displayed when `setState` is called within either `render` or a component constructor. Follow up to #5343 --- src/renderers/shared/reconciler/ReactUpdateQueue.js | 8 +++++--- .../reconciler/__tests__/ReactCompositeComponent-test.js | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/renderers/shared/reconciler/ReactUpdateQueue.js b/src/renderers/shared/reconciler/ReactUpdateQueue.js index 52bbd6a119..55b524c3ba 100644 --- a/src/renderers/shared/reconciler/ReactUpdateQueue.js +++ b/src/renderers/shared/reconciler/ReactUpdateQueue.js @@ -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 ); } diff --git a/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js b/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js index c5ff51e1df..da8259956e 100644 --- a/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js +++ b/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js @@ -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