0

I'm learning how to use Redux and React and found a couple pieces of code in the Redux shopping cart example project:

In the actions/index.js module:

export const addToCart = productId => (dispatch, getState) => {
   if (getState().products.byId[productId].inventory > 0) {
    dispatch(addToCartUnsafe(productId))
  }
}

And in ProductContainer module:

import { addToCart } from '../actions'

export default connect(
  mapStateToProps,
  { addToCart }
)(ProductsContainer) 

I don't understand what the { addToCart } construct means. It looks a little like destructuring but without assinging operator. Can someone point me at what is it and when do we need to use such syntax?

AndreyKo
  • 1,421
  • 2
  • 11
  • 25

1 Answers1

5

{ addToCart } is shortHand for { addToCart: addToCart }

manonthemat
  • 6,101
  • 1
  • 24
  • 49