examples/lit/algolia
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Lit 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-box.tsdebounces the input by 300 ms withcreateDebouncedValuefrom@tanstack/lit-pacerand passes the debounced term to<search-results>.src/search-results.tscallscreateInfiniteQueryControllerwithselectto flattendata.pagesinto one list of hits, plusstaleTimeandgcTime. The "more" button callsfetchNextPageon the controller whilehasNextPageistrue.src/main.tssubclassesQueryClientProviderto set the sharedQueryClientfor the elements inside it.
To run this example:
npm installnpm run dev