mirror of
https://github.com/TanStack/query.git
synced 2026-11-16 22:50:20 +00:00
* chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors * chore(pnpm-lock.yaml): run 'pnpm dedupe' * chore(scripts): move 'oxlint/plugin.ts' to 'oxlint-plugin.ts' to match the flat layout of 'scripts' * chore(pnpm-workspace.yaml): update '@typescript-eslint/parser' and '@typescript-eslint/rule-tester' to '^8.72.1' to match the deduped '@typescript-eslint/utils' |
History
|
|
|---|---|---|
| .. | ||
| public | ||
| src | ||
| .gitignore | ||
| eslint.config.js | ||
| index.html | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.ts | ||
TanStack React 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['products', 'search', indexName, query, hitsPerPage]. Whenqueryis empty,queryFnisskipToken, so nothing is fetched, andgetNextPageParamreturns the next page untilnbPagesis reached.src/services/products/api.tscalls Algolia'ssearchSingleIndexwith the page number and hits per page.src/Search.tsxdebounces the input by 300 ms withuseDebouncedValuefrom TanStack Pacer and passes the debounced term toSearchResults.src/SearchResults.tsxpasses the options touseInfiniteQuerywith aselectthat flattenspagesinto one list of hits, plusstaleTime(30 seconds) andgcTime(15 minutes). The "more" button callsfetchNextPagewhilehasNextPageistrue.
To run this example:
npm installnpm run dev