I see that my code breaks even though prop list is required.
So, should I check for the existence of list before mapping it as I'm doing below?
class Cart extends React.Component {
render() {
const { list } = this.props
return { list && list.map(e => <div> {e} </div>) }
}
}
Cart.propTypes = {
list: PropTypes.array.isRequired
}
UPDATE:
I see suggestions advising to add a default value.
Does it make sense though to both have isRequired and default value set?
Isn't it implied that if a value is required then it should always exists?
But the component seems to mount even though some required props are not satisfied.
So I guess setting default value makes sense, but so isRequire is only a flag for the developer, nothing more, Correct?