Open History to see the last commit
1# TanStack Lit Query Algolia Example
2β
3Searches products on Algolia as you type, with a debounced search term and paginated results loaded with an infinite query.
4β
5## How it works
6β
7- `src/services/products/queries.ts` defines `productsQueries.search()`, an `infiniteQueryOptions` factory keyed by the index, search term, and page size. Its `queryFn` is `skipToken` while the term is empty, and `getNextPageParam` returns the next page until `nbPages` is reached.
8- `src/services/products/api.ts` calls `searchSingleIndex` from `@algolia/client-search` with the page passed in as `pageParam`.
9- `src/search-box.ts` debounces the input by 300 ms with `createDebouncedValue` from `@tanstack/lit-pacer` and passes the debounced term to `<search-results>`.
10- `src/search-results.ts` calls `createInfiniteQueryController` with `select` to flatten `data.pages` into one list of hits, plus `staleTime` and `gcTime`. The "more" button calls `fetchNextPage` on the controller while `hasNextPage` is `true`.
11- `src/main.ts` subclasses `QueryClientProvider` to set the shared `QueryClient` for the elements inside it.
12β
13To run this example:
14β
15- `npm install`
16- `npm run dev`