-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
React: Enforce defaultProps for props that are not required #6077
Comments
Hey there @jendowns! 👋 Sorry about the bug, agreed this rule would have caught it 😞 When trying to enable it on our project, it does seem like this causes a lot of noise for props that most likely don't need a default value. How would you recommend dealing with this? I think the most obvious example in our codebase is |
Hey @joshblack! My instinct here is to proceed to add defaults for |
@jendowns it seems like that would have |
For the default for |
Ugh, I'm definitely a little hesitant to add defaults in this way, but it does seem like the size bug has been pesky. I'm not sure why exactly the defaults aren't being added in and will check with the team. Let me see if there are some other examples of bugs that we could track under this rule to see if we can justify bringing it in. I'm also going to go through and update our Until then, I think we'll keep the rule set stable for now (I'll definitely add in the recommended rules per-plugin) and as I find bugs that would have been fixed by this I'm going to add them to the issue. I think 3 or more would be a good number to justify this change 👍 |
Thanks @joshblack -- the I understand the hesitation & the need to proceed carefully, as it is a LOT to change, but I think it would be very helpful in the long-run to add this rule. And it would encourage good practices around component props. |
Going to close this out since it's been a while, miss you at IBM @jendowns! Hope you're having fun at your current gig 🥳 |
Summary
Please consider requiring defaultProps definition for all props that aren't required.
Specifically, via
react/require-default-props
eslint rule.Justification
Without
defaultProps
, a prop is set toundefined
. Sometimes this isn't a problem, but sometimes it is,as in #6076(actually not exactly relevant in this case)Additional examples of why defaults for non-required props are important can be found in the
react/require-default-props
docs.The text was updated successfully, but these errors were encountered: