title: Redux reducer correct way to check if item already exists in state
body: <p>I'm a little uncertain of this approach when updating an existing or adding a new object to a redux store but am having trouble getting this to work using the accepted methods i.e. Object.assign, update() or spread operators. I can get it working as follows:</p>
  
  <pre><code>const initialState = {
      cart: []
  }
  
  export default function cartReducer(state = initialState, action) {
      switch (action.type) {
  
          case ADD_TO_CART:
  
              let copy = _.clone(state.cart);
              let cartitem = _.find(copy, function (item) {
                  return item.productId === action.payload.productId;
              });
  
              if (cartitem) {
                  cartitem.qty = action.payload.qty;
              } else {
                  copy.push(action.payload);
              }
  
              return {
                  ...state,
                  cart: copy
              }
  
          default:
              return state
      }
  }
  </code></pre>
  
  <p>Although this works, I'm using Underscore to copy the state and check whether the item already exists in state which seems unnecessary and overkill? </p>