Start your All-Access Pass to unlock this challenge
Challenge 2 / 2
In the video, we showed this computed property, which merges the data returned by our watcher with the data that is present in the cart:
completeCart() {
if (!this.cart || !this.products) {
return null;
}
const completeItems = this.cart.items.map((cartItem) => (
{
product: this.products.find((product) => product['@id'] === cartItem.product),
color: cartItem.color,
quantity: cartItem.quantity,
}
));
return {
items: completeItems,
};
},
Take a closer look at the beginning of this function:
if (!this.cart || !this.products) {
return null;
}
Why are we adding this check here? And what would happen if we didn't have it in place?
Skip challenges and go to theNext Chapter