examples/preact/algolia
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Preact 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/services/products/queries.tsdefinesproductsQueries.search(), aninfiniteQueryOptionsfactory keyed by the index, search term, and page size. ItsqueryFnisskipTokenwhile the term is empty, andgetNextPageParamreturns the next page untilnbPagesis reached.src/services/products/api.tscallssearchSingleIndexfrom@algolia/client-searchwith the page passed in aspageParam.src/Search.tsxdebounces the input by 300 ms withuseDebouncedValuefrom@tanstack/preact-pacerand passes the debounced term toSearchResults.src/SearchResults.tsxcallsuseInfiniteQuerywithselectto flattendata.pagesinto one list of hits, plusstaleTimeandgcTime. The "more" button callsfetchNextPagewhilehasNextPageistrue.
To run this example:
npm installnpm run dev