From a2cc3c38e214c16ff6805312d4353c1faab9ff95 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 3 Apr 2018 21:56:21 +0100 Subject: [PATCH] Follow up: make new warning less wordy (#12532) --- .../__tests__/ReactComponentLifeCycle-test.js | 8 +++----- .../__tests__/ReactCompositeComponent-test.js | 16 ++++++---------- packages/react/src/ReactNoopUpdateQueue.js | 9 +++------ 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js b/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js index 5c8488417d33a..965b04f30aaa9 100644 --- a/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js +++ b/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js @@ -215,11 +215,9 @@ describe('ReactComponentLifeCycle', () => { ReactTestUtils.renderIntoDocument(); }).toWarnDev( "Warning: Can't call setState on a component that is not yet mounted. " + - 'This is a no-op, but it might indicate a bug in your application.\n\n' + - 'To fix, assign the initial state in the StatefulComponent constructor. ' + - 'If the state needs to reflect an external data source, ' + - 'you may also add a componentDidMount lifecycle hook to StatefulComponent ' + - 'and call setState there if the external data has changed.', + 'This is a no-op, but it might indicate a bug in your application. ' + + 'Instead, assign to `this.state` directly or define a `state = {};` ' + + 'class property with the desired state in the StatefulComponent component.', ); // Check deduplication; (no extra warnings should be logged). diff --git a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js index 4b8b996467914..216afa8550d3e 100644 --- a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js @@ -239,11 +239,9 @@ describe('ReactCompositeComponent', () => { const container = document.createElement('div'); expect(() => ReactDOM.render(, container)).toWarnDev( "Warning: Can't call forceUpdate on a component that is not yet mounted. " + - 'This is a no-op, but it might indicate a bug in your application.\n\n' + - 'To fix, assign the initial state in the MyComponent constructor. ' + - 'If the state needs to reflect an external data source, ' + - 'you may also add a componentDidMount lifecycle hook to MyComponent ' + - 'and call setState there if the external data has changed.', + 'This is a no-op, but it might indicate a bug in your application. ' + + 'Instead, assign to `this.state` directly or define a `state = {};` ' + + 'class property with the desired state in the MyComponent component.', ); // No additional warning should be recorded @@ -265,11 +263,9 @@ describe('ReactCompositeComponent', () => { const container = document.createElement('div'); expect(() => ReactDOM.render(, container)).toWarnDev( "Warning: Can't call setState on a component that is not yet mounted. " + - 'This is a no-op, but it might indicate a bug in your application.\n\n' + - 'To fix, assign the initial state in the MyComponent constructor. ' + - 'If the state needs to reflect an external data source, ' + - 'you may also add a componentDidMount lifecycle hook to MyComponent ' + - 'and call setState there if the external data has changed.', + 'This is a no-op, but it might indicate a bug in your application. ' + + 'Instead, assign to `this.state` directly or define a `state = {};` ' + + 'class property with the desired state in the MyComponent component.', ); // No additional warning should be recorded diff --git a/packages/react/src/ReactNoopUpdateQueue.js b/packages/react/src/ReactNoopUpdateQueue.js index 3b18c5b8b9b9f..ffd47dacb483a 100644 --- a/packages/react/src/ReactNoopUpdateQueue.js +++ b/packages/react/src/ReactNoopUpdateQueue.js @@ -22,14 +22,11 @@ function warnNoop(publicInstance, callerName) { warning( false, "Can't call %s on a component that is not yet mounted. " + - 'This is a no-op, but it might indicate a bug in your application.\n\n' + - 'To fix, assign the initial state in the %s constructor. ' + - 'If the state needs to reflect an external data source, ' + - 'you may also add a componentDidMount lifecycle hook to %s ' + - 'and call setState there if the external data has changed.', + 'This is a no-op, but it might indicate a bug in your application. ' + + 'Instead, assign to `this.state` directly or define a `state = {};` ' + + 'class property with the desired state in the %s component.', callerName, componentName, - componentName, ); didWarnStateUpdateForUnmountedComponent[warningKey] = true; }