[React] Why is it recommended to mark the props in defaultProps as required?
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
> Note: You don’t need to make foo nullable in your Props type. Flow will make sure that foo is optional if you have a default prop for foo.
I'm trying to understand this decision, but haven't been able to think of a good reason for it. If you think about the `Props` type as the public documentation for the component, wouldn't you want to see which props are actually optional, instead of also having to look at defaultProps?
For example, if we look at a plain old function outside of React that uses object destructuring default values.
```
type Params = {
a: number,
b: number
};
function foo({a, b = 10} : Params) {
console.log(a, b);
}
foo({a: 1}); // Expected error since Params says that `b` is required
```
If you really want `b` to be optional, you can declare it to be optional. Why do we need to special case defaultProps in React?
Contributor guide
Assessment
This issue has not been assessed yet.