📜  redux 的选择器 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:28.660000             🧑  作者: Mango

代码示例1
import { createSelector } from 'reselect';

const getProducts = state => state.products.itemsById;
const getCartItemIds = state => state.currentUser.shoppingCart.itemIds;

export const selectShoppingCartItems = createSelector(
  getProducts,
  getCartItemIds,
  (products, itemIds) => itemIds.map(id => products[id])
);