import React from 'react'; import { useInfiniteHits } from 'react-instantsearch-hooks'; import { InfiniteHits as InfiniteHitsUiComponent } from '../ui/InfiniteHits'; import type { InfiniteHitsProps as InfiniteHitsUiComponentProps } from '../ui/InfiniteHits'; import type { BaseHit, Hit } from 'instantsearch.js'; import type { UseInfiniteHitsProps } from 'react-instantsearch-hooks'; type UiProps = Pick< InfiniteHitsUiComponentProps>, | 'hits' | 'sendEvent' | 'onShowPrevious' | 'onShowMore' | 'isFirstPage' | 'isLastPage' | 'translations' >; export type InfiniteHitsProps = Omit< InfiniteHitsUiComponentProps>, keyof UiProps > & UseInfiniteHitsProps & { /** * Displays the "Show Previous" button when the UI is loaded from a page * beyond the first one. * @default true */ showPrevious?: boolean; translations?: Partial['translations']>; }; export function InfiniteHits({ showPrevious: shouldShowPrevious = true, cache, escapeHTML, showPrevious: userShowPrevious, transformItems, translations, ...props }: InfiniteHitsProps) { const { hits, sendEvent, showPrevious, showMore, isFirstPage, isLastPage } = useInfiniteHits( { cache, escapeHTML, showPrevious: userShowPrevious, transformItems }, { $$widgetType: 'ais.infiniteHits' } ); const uiProps: UiProps = { hits, sendEvent, onShowPrevious: shouldShowPrevious ? showPrevious : undefined, onShowMore: showMore, isFirstPage, isLastPage, translations: { showPreviousButtonText: 'Show previous results', showMoreButtonText: 'Show more results', ...translations, }, }; return ; }