'use client'; import React from 'react'; import type { ShopifyProduct } from '@reacteditor/field-shopify'; import { useProduct, useProductRecommendations, } from '@/hooks/use-shopify-products'; import { useRouteSegment } from '@/hooks/use-route-segment'; import { ProductCard } from './product-card'; export type ProductRecommendationsProps = { product: ShopifyProduct | null; heading: string; limit: number; }; export function ProductRecommendationsView({ product: selected, heading, limit, }: ProductRecommendationsProps) { const routeHandle = useRouteSegment(); const handle = selected?.handle ?? routeHandle ?? null; const { product } = useProduct(handle); const { recommendations, loading, error } = useProductRecommendations( product?.id ?? null, ); // Don't show section if we're not loading and have no recommendations if (!loading && (!recommendations || recommendations.length === 0)) { return null; } return (
Recommendations could not be loaded