Skip to content

Commit

Permalink
docs: Document how to resume pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Feb 25, 2025
1 parent 885d785 commit edd20b6
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,38 @@ if (hasNextPage) {
}
```

#### Resume pagination

Get the first page on initial load:

```ts
const params = { limit: 20 }

const pages = seam.createPaginator(
seam.devices.list(params)
)

const [devices, pagination] = await pages.firstPage()

localStorage.setItem('/seam/devices/list', JSON.stringify([params, pagination]))
```

Get the next page at a later time:

```ts
const [params = {}, { hasNextPage = false, nextPageCursor = null } = {}] = JSON.parse(
localStorage.getItem('/seam/devices/list') ?? '[]'
)

const pages = seam.createPaginator(
seam.devices.list(params)
)

if (hasNextPage) {
const [moreDevices] = await pages.nextPage(nextPageCursor)
}
```

#### Iterate over all pages

```ts
Expand Down

0 comments on commit edd20b6

Please sign in to comment.