New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for undefined values of defaultProps #1153
Comments
Why is that a problem? The point of the rule is that defaultProps are explicit' it doesn't matter at all what their value is. |
Specifying const Component = ({ min, max )} => (
<div>{typeof min}/{typeof max}</div>; // <div>undefined/undefined</div>
);
Component.propTypes = {
min: PropTypes.number,
max: PropTypes.number,
};
Component.defaultProps = {
min: undefined,
// max: undefined,
};
|
It's not required by JavaScript. It's required by this rule, since an explicit undefined is much much better than an implicit one. |
TBH I think @Shutnik is right and sorry, but, @ljharb , explicit undefined is much much better is your opinion. would you ever do something like this because explicit undefined is much much better?
I don't see the foundation of @ljharb explanation... I think a good trade-off is leave the possibility to omit the default prop only if the propType is object, node, element and maybe an array |
@enricotelesca yes, and in fact that would increase performance of |
Using
require-default-props
rule following code is considered as valid:But actually this code works like:
So it would be great if
require-default-props
rule will also check that case and throw errors fordefaultProps
keys with undefined values.The text was updated successfully, but these errors were encountered: