Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

example.component.html

39 lines1.2 KB

1<div>
2 <p>
3 In this example, each page of data remains visible as the next page is
4 fetched. The buttons and capability to proceed to the next page are also
5 suppressed until the next page cursor is known. Each page is cached as a
6 normal query too, so when going to previous pages, you'll see them
7 instantaneously while they are also refetched invisibly in the background.
8 </p>
9​
10 @if (query.isPending()) {
11 <div>Loading...</div>
12 } @else if (query.isError()) {
13 <div>Error: {{ query.error().message }}</div>
14 } @else if (query.isSuccess()) {
15 <div>
16 @for (project of query.data().projects; track project.id) {
17 <p>{{ project.name }}</p>
18 }
19 </div>
20 }
21​
22 <div>Current Page: {{ page() + 1 }}</div>
23​
24 <button (click)="previousPage()" [disabled]="page() === 0">
25 Previous Page
26 </button>
27 <button
28 (click)="nextPage()"
29 [disabled]="query.isPlaceholderData() || !query.data()?.hasMore"
30 >
31 Next Page
32 </button>
33 <!-- Since the last page's data potentially sticks around between page requests, -->
34 <!-- we can use `isFetching` to show a background loading -->
35 <!-- indicator since our `status === 'pending'` state won't be triggered -->
36 @if (query.isFetching()) {
37 <span>Loading...</span>
38 }
39</div>