Open History to see the last commit
TanStack Vue 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/api.tscallssearchSingleIndexfrom@algolia/client-searchwith the query, page andhitsPerPage, and returns thehitsandnbPages.src/services/products/queries.tsdefinesproductsQueries.search(...), aninfiniteQueryOptionsfactory keyed by['products', 'search', indexName, query, hitsPerPage]. It usesskipTokenas thequeryFnwhile the query is empty, starts atinitialPageParam: 0, andgetNextPageParamstops atnbPages.src/SearchBox.vuedebounces the input by 300 ms withuseDebouncedValuefrom@tanstack/vue-pacerand passes the debounced value to the results.src/SearchResults.vuepasses a getter touseInfiniteQuerywithstaleTimeandgcTimeadded, flattensdata.pagesinto one list, and loads more withfetchNextPagewhilehasNextPageistrue.
To run this example:
npm installnpm run dev