In this lesson we'll shift the responsibility of managing the state of our application over to a higher-order component rather than having each component managing it's own state.
In app-catalog, how does the catalog keep up with the quantity of items in the cart? I'm not getting that data on the props (the item.qty) from the getCatalog() function of AppStore.getCatalog(). Thanks.
It all happens here in app-store.js
getCatalog(){
return _catalog.map(item => {
return Object.assign( {}, item, _cartItems.find( cItem => cItem.id === item.id))
})
},
We map cart item's qty onto the items in a clone of _catalog
Thanks, this cleared it up for me!
getCatalog(){
return _catalog.map(item => {
return Object.assign({}, item, _cartItems.find(cItem => cItem.id === item.id))
})
}
Just wondering if I've written this code down wrong and can't see the mistake because I can't seem to merge the data and get the 'id' property to show up on the '_catalog' data. It exists in the '_cartItems' when I add one to cart.
At 2:06 you replace a function with an invoked function, why does it still work? Also, on line 7 you simply pass in props but on line 17 you pass in this.props, why the difference? Many thanks for the great series!
Can you share an example showing how to leverage the higher order component callback for componentDidMount? Would I pass in an additional callback?