title: How to calculate the total price of all items in reducer?
body: <p>I am trying to build a shoppingcart app in reactjs/redux and this is 1 of my reducers:</p>
  
  <pre><code>const initialState = {
      items: [],
      cartOpen:true
  }
  
      const Cart = (state = initialState, action) =&gt; {
          switch (action.type) {
              case 'ADD_TO_CART':
                  return [...state, action.payload]
              default:
                  return state
          }
      }
  
      export default Cart;
  </code></pre>
  
  <p>The other reducer contains the data ie items for the app:</p>
  
  <pre><code>const Data = (state = initialState, action) =&gt; {
      switch (action.type) {
          case 'GET_DATA_SUCCESS':
              return Object.assign({}, state, { datas: action.data });
          case 'GET_DATA_FAIL':
              return Object.assign({}, state, { datas: action.data });
  
          default:
              return state
      }
  }
  </code></pre>
  
  <p>When the ADD_TO_CART action is dispatched I want to calculate the new total for the cart. I am looking for a way to calculate the total price of al the items in the cart when the cart is updated.</p>