Skip to content

Commit 0b54ed3

Browse files
committed
Tweak da message
1 parent ec8474c commit 0b54ed3

8 files changed

+36
-14
lines changed

Diff for: packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1003,8 +1003,10 @@ describe('ReactComponentLifeCycle', () => {
10031003

10041004
const div = document.createElement('div');
10051005
expect(() => ReactDOM.render(<MyComponent />, div)).toWarnDev(
1006-
'MyComponent: Component state must be properly initialized when using getDerivedStateFromProps. ' +
1007-
'Expected state to be an object, but it was undefined.',
1006+
'`MyComponent` uses `getDerivedStateFromProps` but its initial state is ' +
1007+
'undefined. This is not recommended. Instead, define the initial state by ' +
1008+
'assigning an object to `this.state` in the constructor of `MyComponent`. ' +
1009+
'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.',
10081010
{withoutStack: true},
10091011
);
10101012

Diff for: packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ describe('ReactDOMServerLifecycles', () => {
201201
}
202202

203203
expect(() => ReactDOMServer.renderToString(<Component />)).toWarnDev(
204-
'Component: Component state must be properly initialized when using getDerivedStateFromProps. ' +
205-
'Expected state to be an object, but it was undefined.',
204+
'`Component` uses `getDerivedStateFromProps` but its initial state is ' +
205+
'undefined. This is not recommended. Instead, define the initial state by ' +
206+
'assigning an object to `this.state` in the constructor of `Component`. ' +
207+
'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.',
206208
{withoutStack: true},
207209
);
208210

Diff for: packages/react-dom/src/server/ReactPartialRenderer.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,13 @@ function resolve(
476476
if (!didWarnAboutUninitializedState[componentName]) {
477477
warningWithoutStack(
478478
false,
479-
'%s: Component state must be properly initialized when using getDerivedStateFromProps. ' +
480-
'Expected state to be an object, but it was %s.',
479+
'`%s` uses `getDerivedStateFromProps` but its initial state is ' +
480+
'%s. This is not recommended. Instead, define the initial state by ' +
481+
'assigning an object to `this.state` in the constructor of `%s`. ' +
482+
'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.',
481483
componentName,
482484
inst.state === null ? 'null' : 'undefined',
485+
componentName,
483486
);
484487
didWarnAboutUninitializedState[componentName] = true;
485488
}

Diff for: packages/react-reconciler/src/ReactFiberClassComponent.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,13 @@ function constructClassInstance(
505505
didWarnAboutUninitializedState.add(componentName);
506506
warningWithoutStack(
507507
false,
508-
'%s: Component state must be properly initialized when using getDerivedStateFromProps. ' +
509-
'Expected state to be an object, but it was %s.',
508+
'`%s` uses `getDerivedStateFromProps` but its initial state is ' +
509+
'%s. This is not recommended. Instead, define the initial state by ' +
510+
'assigning an object to `this.state` in the constructor of `%s`. ' +
511+
'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.',
510512
componentName,
511513
instance.state === null ? 'null' : 'undefined',
514+
componentName,
512515
);
513516
}
514517
}

Diff for: packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee

+6-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,12 @@ describe 'ReactCoffeeScriptClass', ->
163163
}
164164
expect(->
165165
ReactDOM.render(React.createElement(Foo, foo: 'foo'), container)
166-
).toWarnDev 'Foo: Component state must be properly initialized when using getDerivedStateFromProps. Expected state to be an object, but it was undefined.', {withoutStack: true}
166+
).toWarnDev (
167+
'`Foo` uses `getDerivedStateFromProps` but its initial state is ' +
168+
'undefined. This is not recommended. Instead, define the initial state by ' +
169+
'assigning an object to `this.state` in the constructor of `Foo`. ' +
170+
'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.'
171+
), {withoutStack: true}
167172
undefined
168173

169174
it 'updates initial state with values returned by static getDerivedStateFromProps', ->

Diff for: packages/react/src/__tests__/ReactES6Class-test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,10 @@ describe('ReactES6Class', () => {
190190
}
191191
}
192192
expect(() => ReactDOM.render(<Foo foo="foo" />, container)).toWarnDev(
193-
'Foo: Component state must be properly initialized when using getDerivedStateFromProps. ' +
194-
'Expected state to be an object, but it was undefined.',
193+
'`Foo` uses `getDerivedStateFromProps` but its initial state is ' +
194+
'undefined. This is not recommended. Instead, define the initial state by ' +
195+
'assigning an object to `this.state` in the constructor of `Foo`. ' +
196+
'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.',
195197
{withoutStack: true},
196198
);
197199
});

Diff for: packages/react/src/__tests__/ReactTypeScriptClass-test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,10 @@ describe('ReactTypeScriptClass', function() {
448448
expect(function() {
449449
ReactDOM.render(React.createElement(Foo, {foo: 'foo'}), container);
450450
}).toWarnDev(
451-
'Foo: Component state must be properly initialized when using getDerivedStateFromProps. ' +
452-
'Expected state to be an object, but it was undefined.',
451+
'`Foo` uses `getDerivedStateFromProps` but its initial state is ' +
452+
'undefined. This is not recommended. Instead, define the initial state by ' +
453+
'assigning an object to `this.state` in the constructor of `Foo`. ' +
454+
'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.',
453455
{withoutStack: true}
454456
);
455457
});

Diff for: packages/react/src/__tests__/createReactClassIntegration-test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,10 @@ describe('create-react-class-integration', () => {
511511
expect(() =>
512512
ReactDOM.render(<Component />, document.createElement('div')),
513513
).toWarnDev(
514-
'Component state must be properly initialized when using getDerivedStateFromProps.',
514+
'`Component` uses `getDerivedStateFromProps` but its initial state is ' +
515+
'undefined. This is not recommended. Instead, define the initial state by ' +
516+
'assigning an object to `this.state` in the constructor of `Component`. ' +
517+
'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.',
515518
{
516519
withoutStack: true,
517520
},

0 commit comments

Comments
 (0)