When I see an optional React component prop in a code review, I dig deeper: 1


When I see an optional React component prop in a code review, I dig deeper:

1. What happens when the prop is omitted? Is there a default?

2. Is it a single-use component? If so, all props should be required.

3. Is the prop necessary for the component to work? If so, it should be required.
Sometimes, a prop is optional because it’s optional in the parent. But if the child requires it, the child component's props should require it.

This assures the child is passed valid props. It's the parent's responsibility to pass a valid prop, or not render the child.

View original on X