I have default props in my React component:
PropertyTitleLabel.defaultProps = { bedrooms: 1, propertyType: 'flat' }; PropertyTitleLabel.propTypes = { bedrooms: PropTypes.number, propertyType: PropTypes.string };
But when I'm passing null to bedrooms like:
null
bedrooms
const bedrooms = null; // in real world API returns `null` <Component bedrooms={bedrooms} />
It's not replaced with default prop :( Any ideas?
You can change the null value to undefined to use the default value.
undefined
<Component bedrooms={bedrooms || undefined} />
2.1m questions
2.1m answers
60 comments
57.0k users