Follow up: make new warning less wordy (#12532)
Dan Abramov committed
Apr 3, 2018 at 21:56 UTC
a2cc3c38e214c16ff6805312d4353c1faab9ff95
3 files changed
+12
-21
packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js
+3
-5
@@ -215,11 +215,9 @@ describe('ReactComponentLifeCycle', () => {
215
ReactTestUtils.renderIntoDocument(<StatefulComponent />);
216
}).toWarnDev(
217
"Warning: Can't call setState on a component that is not yet mounted. " +
218
- 'This is a no-op, but it might indicate a bug in your application.\n\n' +
219
- 'To fix, assign the initial state in the StatefulComponent constructor. ' +
220
- 'If the state needs to reflect an external data source, ' +
221
- 'you may also add a componentDidMount lifecycle hook to StatefulComponent ' +
222
- 'and call setState there if the external data has changed.',
218
+ 'This is a no-op, but it might indicate a bug in your application. ' +
219
+ 'Instead, assign to `this.state` directly or define a `state = {};` ' +
220
+ 'class property with the desired state in the StatefulComponent component.',
221
);
222
223
// Check deduplication; (no extra warnings should be logged).
packages/react-dom/src/__tests__/ReactCompositeComponent-test.js
+6
-10
@@ -239,11 +239,9 @@ describe('ReactCompositeComponent', () => {
239
const container = document.createElement('div');
240
expect(() => ReactDOM.render(<MyComponent />, container)).toWarnDev(
241
"Warning: Can't call forceUpdate on a component that is not yet mounted. " +
242
- 'This is a no-op, but it might indicate a bug in your application.\n\n' +
243
- 'To fix, assign the initial state in the MyComponent constructor. ' +
244
- 'If the state needs to reflect an external data source, ' +
245
- 'you may also add a componentDidMount lifecycle hook to MyComponent ' +
246
- 'and call setState there if the external data has changed.',
242
+ 'This is a no-op, but it might indicate a bug in your application. ' +
243
+ 'Instead, assign to `this.state` directly or define a `state = {};` ' +
244
+ 'class property with the desired state in the MyComponent component.',
245
);
246
247
// No additional warning should be recorded
@@ -265,11 +263,9 @@ describe('ReactCompositeComponent', () => {
263
const container = document.createElement('div');
264
expect(() => ReactDOM.render(<MyComponent />, container)).toWarnDev(
265
"Warning: Can't call setState on a component that is not yet mounted. " +
268
- 'This is a no-op, but it might indicate a bug in your application.\n\n' +
269
- 'To fix, assign the initial state in the MyComponent constructor. ' +
270
- 'If the state needs to reflect an external data source, ' +
271
- 'you may also add a componentDidMount lifecycle hook to MyComponent ' +
272
- 'and call setState there if the external data has changed.',
266
+ 'This is a no-op, but it might indicate a bug in your application. ' +
267
+ 'Instead, assign to `this.state` directly or define a `state = {};` ' +
268
+ 'class property with the desired state in the MyComponent component.',
269
);
270
271
// No additional warning should be recorded
packages/react/src/ReactNoopUpdateQueue.js
+3
-6
@@ -22,14 +22,11 @@ function warnNoop(publicInstance, callerName) {
22
warning(
23
false,
24
"Can't call %s on a component that is not yet mounted. " +
25
- 'This is a no-op, but it might indicate a bug in your application.\n\n' +
26
- 'To fix, assign the initial state in the %s constructor. ' +
27
- 'If the state needs to reflect an external data source, ' +
28
- 'you may also add a componentDidMount lifecycle hook to %s ' +
29
- 'and call setState there if the external data has changed.',
25
+ 'This is a no-op, but it might indicate a bug in your application. ' +
26
+ 'Instead, assign to `this.state` directly or define a `state = {};` ' +
27
+ 'class property with the desired state in the %s component.',
28
callerName,
29
componentName,
32
- componentName,
30
);
31
didWarnStateUpdateForUnmountedComponent[warningKey] = true;
32
}