examples/lit/infinite-query-with-max-pages
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Lit Query Infinite Query With Max Pages Example#
An infinite list that loads pages in both directions and keeps at most 3 pages in the cache with maxPages.
How it works#
src/services/projects/queries.tsdefinesprojectsQueries.infinite(), aninfiniteQueryOptionsfactory withinitialPageParam: 0,getNextPageParamandgetPreviousPageParamthat readnextIdandpreviousId, andmaxPages: 3.src/main.tspasses it tocreateInfiniteQueryController. "Load Older" callsfetchPreviousPageand "Load Newer" callsfetchNextPageon the controller, and once 3 pages are cached, loading a page in one direction drops the page at the other end.src/mocks.tsis an MSW handler for/api/projectsthat returns 4 projects per cursor after a 300 ms delay.nextIdisnullonce the cursor reaches 20, andpreviousIdisnullonce it reaches -20.
To run this example:
npm installnpm run dev