Skip to content

Commit 60928e3

Browse files
committed
Remove defaultProps support (except for classes) (#28733)
This removes defaultProps support for all component types except for classes. We've chosen to continue supporting defaultProps for classes because lots of older code relies on it, and unlike function components, (which can use default params), there's no straightforward alternative. By implication, it also removes support for setting defaultProps on `React.lazy` wrapper. So this will not work: ```js const MyClassComponent = React.lazy(() => import('./MyClassComponent')); // MyClassComponent is not actually a class; it's a lazy wrapper. So // defaultProps does not work. MyClassComponent.defaultProps = { foo: 'bar' }; ``` However, if you set the default props on the class itself, then it's fine. For classes, this change also moves where defaultProps are resolved. Previously, defaultProps were resolved by the JSX runtime. This change is only observable if you introspect a JSX element, which is relatively rare but does happen. In other words, previously `<ClassWithDefaultProp />.props.aDefaultProp` would resolve to the default prop value, but now it does not. DiffTrain build for [48b4ecc](48b4ecc)
1 parent e45e8f3 commit 60928e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+111074
-112990
lines changed

compiled/facebook-www/JSXDEVRuntime-dev.classic.js

Lines changed: 62 additions & 338 deletions
Large diffs are not rendered by default.

compiled/facebook-www/JSXDEVRuntime-dev.modern.js

Lines changed: 62 additions & 340 deletions
Large diffs are not rendered by default.

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
da69b6af9697b8042834644b14d0e715d4ace18a
1+
48b4ecc9012638ed51b275aad24b2086b8215e32

0 commit comments

Comments
 (0)