score:3

Accepted answer

you open an object literal, start with ...state to spread that out into the new object, and follow it with the cart property (and the same concept for the inner one):

case increase_quantity: {
  return {
    ...state,
    cart: state.cart.map(item => {
      if (item.product.id === action.productinfo.product.id) {
        return {
          ...item,
          quantity: action.quantity + 1,
        };
      }
      return item;
    }),
  };
}

by doing it in that order, you ensure that cart (or quantity for the inner one) overrides the property from the spread. later properties in in object literals "win" over earlier ones.

score:1

object.assign({}, item, { quantity: action.quantity + 1 });
becomes
{ ...item, quantity: action.quantity + 1 }

case increase_quantity : {
    return {
        ...state,
        cart : state.cart.map(item => {
            if (item.product.id === action.productinfo.product.id) {
                return {
                    ...item,
                    quantity: action.quantity + 1
                }
            }
            return item;
        })
    };
}

Related Query

More Query from same tag