Advertisement
rodrigofbm

cart.selectors.js

Dec 16th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { createSelector } from "reselect";
  2.  
  3. const selectCart = state => state.cart;
  4.  
  5. export const selectCartItems = createSelector(
  6.   [selectCart],
  7.   cart => cart.cartItems
  8. );
  9.  
  10. export const selectCartItemsCount = createSelector(
  11.   [selectCartItems],
  12.   cartItems =>
  13.     cartItems.reduce(
  14.       (accumulatedQuantity, item) => accumulatedQuantity + item.quantity,
  15.       0
  16.     )
  17. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement