Alternative defaultProps not working with component syntax
neutraali opened this issue · 1 comments
Flow version: 0.235.1
Expected behavior
defaultProps
works when declaring it as:
type Props = {
name: string
}
component Test(...props: Props) {
return <h1>{`Hello ${props.name}!`}</h1>;
}
component.defaultProps = {
name: 'World'
}
Actual behavior
Cannot assign object literal to "Test.defaultProps" because property
defaultProps is missing in "React.AbstractComponentStatics"
At the end of the docs detaling React class/function components, there's an "alternative" way to declare defaultProps
which we have been using so far. However, this doesn't quite seem to work with component syntax, which is kinda weird because one would assume that they largely follow the rules for functional components.
Is this intentional?
This is intentional. Note that it will stop working for functions as well starting from React 19: https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-proptypes-and-defaultprops