Pagination#
RTK Query makes it straightforward to integrate with a standard index-based pagination API. This is the most common form of pagination that you'll need to implement.
Setup an endpoint to accept a page arg#
- TypeScript
- JavaScript
src/app/services/posts.ts
src/app/services/posts.ts
Trigger the next page by incrementing the page state variable#
src/features/posts/PostsManager.tsx
Example#
In the following example, you'll see Loading on the initial query, but then as you move forward we'll use the next/previous buttons as a fetching indicator while any non-cached query is performed. When you go back, the cached data will be served instantaneously.