File size: 1,273 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<div>
  <p>
    In this example, each page of data remains visible as the next page is
    fetched. The buttons and capability to proceed to the next page are also
    supressed until the next page cursor is known. Each page is cached as a
    normal query too, so when going to previous pages, you'll see them
    instantaneously while they are also refetched invisibly in the background.
  </p>

  @if (query.isPending()) {
    <div>Loading...</div>
  } @else if (query.isError()) {
    <div>Error: {{ query.error().message }}</div>
  } @else if (query.isSuccess()) {
    <div>
      @for (project of query.data().projects; track project.id) {
        <p>{{ project.name }}</p>
      }
    </div>
  }

  <div>Current Page: {{ page() + 1 }}</div>

  <button (click)="previousPage()" [disabled]="page() === 0">
    Previous Page
  </button>
  <button
    (click)="nextPage()"
    [disabled]="query.isPlaceholderData() || !query.data()?.hasMore"
  >
    Next Page
  </button>
  <!-- Since the last page's data potentially sticks around between page requests, -->
  <!-- we can use `isFetching` to show a background loading -->
  <!-- indicator since our `status === 'pending'` state won't be triggered -->
  @if (query.isFetching()) {
    <span>Loading...</span>
  }
</div>