import useAlgolia from './useAlgolia' type Product = { name: string shortDescription: string salePrice: number } type SearchResultsProps = { query: string } export default function SearchResults({ query = '' }: SearchResultsProps) { const { hits, isLoading, isFetching, status, hasNextPage, isFetchingNextPage, fetchNextPage, } = useAlgolia({ indexName: 'bestbuy', query, hitsPerPage: 5, staleTime: 1000 * 30, // 30s gcTime: 1000 * 60 * 15, // 15m }) if (!query) return null if (isLoading) return
Loading...
return (
Status: {status} {isFetching && fetching...}
{hits && hits.length > 0 ? ( hits.map((product) => (
  • {product.name} {product.shortDescription && ( <>
    {product.shortDescription} )}
    ${product.salePrice}
  • )) ) : (

    No products found!

    )}
    {hasNextPage && (
    fetchNextPage()}> more
    )} {isFetchingNextPage && (
    Fetching next page...
    )}
    ) }