question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React: Enforce defaultProps for props that are not required

See original GitHub issue

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 to undefined. 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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
joshblackcommented, Mar 3, 2021

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 🥳

1reaction
joshblackcommented, May 13, 2020

@jendowns it seems like that would have '' as the default for className, what would you recommend as a default for children?

Read more comments on GitHub >

github_iconTop Results From Across the Web

A complete guide to React default props - LogRocket Blog
Cover three ways to implement default props in React and provide default values for props that are not required by the component.
Read more >
Typechecking With PropTypes - React
The defaultProps will be used to ensure that this.props.name will have a value if it was not specified by the parent component. The...
Read more >
propType "name" is not required, but has no corresponding ...
First is to use defaultProps directly, which is deprecated for function components. In your case it would look like:
Read more >
React: Everything about Default Props | by Chidume Nnamdi
The Solution — defaultProps ... To solve this issue, we can use the logical operator || to set a fallback value, so when...
Read more >
React with TypeScript: Optional Props with Default Values
But what if we want default values for our optional props in the case when they are not specified? ... We can then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found