Skip to content

Commit c8740a7

Browse files
committed
On non-legacy components, initialize state, if undefined
1 parent b397195 commit c8740a7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/traceLifecycle.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export default function traceLifecycle(ComponentToTrace) {
5454
constants.DEPRECATED_THIS_TRACE,
5555
props.trace
5656
);
57+
if (!isLegacy && typeof this.state === 'undefined') {
58+
this.state = {};
59+
// Initialize state if it is undefined, otherwise the addition of getDerivedStateFromProps will cause a warning.
60+
}
5761
}
5862

5963
componentWillMount() {

0 commit comments

Comments
 (0)