I'm using es6 object destructuring to provide default parameters to a function.
function mapStateToProps({ shops: { cakeShop: {}, pieShop: {} }) {
return {
CakeShopName: shops.cakeShop.Name,
PieShopName: shops.pieShop.Name
}
}
The problem with the above is that if I call
mapStateToProps({})
The code throws Cannot read property 'Name' of undefined
. The nested objects on shops
are not set to their default values and the code has a null reference.
How can I make sure that the nested objects within shops
are being set to the right default value, even if shops
itself is defined?