Files
kakawa/src/lib/product-by-handle.tsx
2024-09-26 09:50:24 +05:30

17 lines
445 B
TypeScript

import { cache } from 'react';
import { medusaClient } from '@/lib/config';
import { PricedProduct } from '@medusajs/medusa/dist/types/pricing';
export const getProductByHandle = cache(async function (
handle: string,
): Promise<{ product: PricedProduct }> {
const product = await medusaClient.products
.list({ handle })
.then(({ products }) => products[0])
.catch((err) => {
throw err;
});
return { product };
});