Skip to content

Commit a2cc3c3

Browse files
authored
Follow up: make new warning less wordy (#12532)
1 parent 36c2939 commit a2cc3c3

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,9 @@ describe('ReactComponentLifeCycle', () => {
215215
ReactTestUtils.renderIntoDocument(<StatefulComponent />);
216216
}).toWarnDev(
217217
"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.',
223221
);
224222

225223
// Check deduplication; (no extra warnings should be logged).

packages/react-dom/src/__tests__/ReactCompositeComponent-test.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,9 @@ describe('ReactCompositeComponent', () => {
239239
const container = document.createElement('div');
240240
expect(() => ReactDOM.render(<MyComponent />, container)).toWarnDev(
241241
"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.',
247245
);
248246

249247
// No additional warning should be recorded
@@ -265,11 +263,9 @@ describe('ReactCompositeComponent', () => {
265263
const container = document.createElement('div');
266264
expect(() => ReactDOM.render(<MyComponent />, container)).toWarnDev(
267265
"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.',
273269
);
274270

275271
// No additional warning should be recorded

packages/react/src/ReactNoopUpdateQueue.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ function warnNoop(publicInstance, callerName) {
2222
warning(
2323
false,
2424
"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.',
3028
callerName,
3129
componentName,
32-
componentName,
3330
);
3431
didWarnStateUpdateForUnmountedComponent[warningKey] = true;
3532
}

0 commit comments

Comments
 (0)