Flux Architecture: Higher-Order Components

InstructorJoe Maddalone

Share this video with your friends

Send Tweet

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.

nader dabit
~ 9 years ago

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.

Joe Maddaloneinstructor
~ 9 years ago

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

nader dabit
~ 9 years ago

Thanks, this cleared it up for me!

Keir Beckett
~ 9 years ago

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.

Steven
~ 8 years ago

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!

Andrew
~ 7 years ago

Can you share an example showing how to leverage the higher order component callback for componentDidMount? Would I pass in an additional callback?