@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 622 B
JavaScript
"use client";
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";const actionType=["getSkuList","setSkuList"];export const skuListsInitialState={listIds:[]},getSkuList=async({listIds,config,dispatch})=>{const skuLists={};try{const sdk=getSdk(config);listIds.forEach(async id=>{const skuCodes=(await sdk.sku_lists.retrieve(id,{include:["skus"],fields:{skus:["code"]}})).skus;skuLists[id]=skuCodes}),dispatch({payload:{skuLists},type:"getSkuList"})}catch(error){console.error(error)}};const skuListsReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default skuListsReducer;