Tip: When creating a new React component, start by requiring all props
Tip: When creating a new React component, start by requiring all props. Why?
1 Handling the null case requires extra code
2 It's easy to forget to handle missing prop values
3 Optional props increase complexity
So: Require props/use defaults until the optional prop is justified.
I just reviewed a large code base of 100s of components and virtually all props were optional. That's a huge surface area for potential bugs.
Required props also make a component easier to understand because it states clearly what's necessary to use it.