examples/svelte/algolia
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Svelte Query Algolia Example#
Searches products on Algolia as you type, with a debounced search term and paginated results loaded with an infinite query.
How it works#
src/lib/services/products/queries.tsdefinesproductsQueries.search(...), aninfiniteQueryOptionsfactory keyed by['products', 'search', indexName, query, hitsPerPage]. It usesskipTokenwhile the search term is empty, andgetNextPageParamstops at the last page reported by Algolia.src/lib/services/products/api.tscalls Algolia'ssearchSingleIndexwith the page number frompageParam.src/lib/Search.sveltedebounces the input by 300 ms withcreateDebouncedValuefrom TanStack Pacer and passes the debounced term tosrc/lib/SearchResults.svelte.src/lib/SearchResults.sveltepasses the options tocreateInfiniteQuerywith a 30-secondstaleTimeand aselectthat flattensdata.pagesinto one list, and loads more results withfetchNextPagewhilehasNextPageistrue.
To run this example:
npm installnpm run dev