Description
React 19 sees the dropping of propTypes
and defaultProps
for function components.
The change to defaultProps
is of particular interest because it has a runtime impact (ignoring any caveats/special cases for propTypes
in this issue) - for like for like behaviour consumers are now forced to migrate to ES6 style default arguments (or alternatives, e.g. hoist the default to the parent component etc).
I would be interested to test appetite for either a new rule, or adjustments to existing rule(s), to allow consumers of this lint plugin to forbid usage of defaultProps
on non-class components (assuming I’ve not overlooked existing support for this in some form).
Eventually I could see such a rule becoming redundant once sufficient time has passed such that the general React community has forgotten about defaultProps
etc., but in the meantime such a rule would help to protect React community component authors from themselves where years of habit results in them reaching for the API which silently does nothing (*silent in production, with logged warnings/errors in development).
Because of this habit I suspect current themes of disabling certain rule capabilities (manually or automatically by detecting R19+) in other issues doesn’t quite cut it? Some form of opt-in (manual or automatically for R19+) behaviour to warn users that they’ve accidentally introduced defaultProps
would be fab.
Related discussions: