Closed anddero closed 2 years ago
If I want to conditionally render some component, I could use the following pattern:
function MyOptionalComponent(props) { if (props.optionalValue === null) return null; // otherwise return something rendered from that optionalValue object ... }
If I provide the proptypes for this component:
MyOptionalComponent.propTypes = { optionalValue: PropTypes.shape({ field: PropTypes.string, anotherField: PropTypes.number }) };
I will always get a warning at the null-check of the component function:
Condition is always false since types '{field: String, anotherField: Number' and 'null' have no overlap
I did not make optionalValue required, therefore it should be optional, therefore there should be no such warning.
optionalValue
"prop-types": "15.7.2", "react": "16.8.6"
This warning seems like it might be coming from flow, since propTypes don’t have a warning of this kind.
If I want to conditionally render some component, I could use the following pattern:
If I provide the proptypes for this component:
I will always get a warning at the null-check of the component function:
I did not make
optionalValue
required, therefore it should be optional, therefore there should be no such warning.