Skip to content

Commit 39f9b26

Browse files
committed
Tweak da message
1 parent ec8474c commit 39f9b26

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

packages/react-reconciler/src/ReactFiberClassComponent.js

Lines changed: 5 additions & 2 deletions
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
}

packages/react/src/__tests__/ReactES6Class-test.js

Lines changed: 4 additions & 2 deletions
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
});

packages/react/src/__tests__/ReactTypeScriptClass-test.ts

Lines changed: 4 additions & 2 deletions
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
});

packages/react/src/__tests__/createReactClassIntegration-test.js

Lines changed: 4 additions & 1 deletion
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)