examples/angular/infinite-query-with-max-pages
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Angular 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/app/services/projects/queries.tsis an@InjectableProjectsQuerieswhoselist()returnsinfiniteQueryOptionswithinitialPageParam: 0andgetPreviousPageParamandgetNextPageParamreading the page'spreviousIdandnextId.src/app/components/example.component.tsspreadslist()intoinjectInfiniteQuerywithmaxPages: 3, so loading a fourth page drops the page at the other end. It derives the button labels and disabled states withcomputedfromhasNextPage,hasPreviousPage,isFetchingNextPageandisFetchingPreviousPage.src/app/components/example.component.htmlrenders every page indata().pages, with "Load Older" callingfetchPreviousPage()and "Load newer" callingfetchNextPage().src/app/interceptor/projects-mock.interceptor.tsis anHttpInterceptorFn, registered withwithInterceptorsinsrc/app/app.config.ts, that answers/api/projectswith 4 projects per cursor after 100 to 500 ms, withnextIdandpreviousIdset tonullpast cursor 20 and -20.
To run this example:
npm installnpm start