import {useMemo} from 'react' import {useShopActionInfiniteQuery} from '../../internal/reactQuery' import {useShopActions} from '../../internal/useShopActions' import { PaginatedDataHookOptionsBase, PaginatedDataHookReturnsBase, Product, } from '../../types' export interface UseRecentProductsParams extends PaginatedDataHookOptionsBase { includeSensitive?: boolean } export interface UseRecentProductsReturns extends PaginatedDataHookReturnsBase { products: Product[] | null } /** * Hook to fetch recently viewed products. * @param params - Options for the hook. */ export const useRecentProducts = ( params?: UseRecentProductsParams ): UseRecentProductsReturns => { const {getRecentProducts} = useShopActions() const {skip, ...shopActionParams} = params ?? {} const {data, ...rest} = useShopActionInfiniteQuery( ['recentProducts', shopActionParams], getRecentProducts, shopActionParams, {skip} ) const products = useMemo(() => { return data ?? null }, [data]) return { ...rest, products, } } /** * The `useRecentProducts` hook fetches products the user recently viewed in the Shop app, ordered by recency. You can use this to create 'Continue Shopping' sections or personalized product recommendations based on browsing history. * @publicDocs */ export type UseRecentProductsGeneratedType = ( params?: UseRecentProductsParams ) => UseRecentProductsReturns