Overview
paginatedAsyncAction extends asyncAction with a dedicated page cursor and helpers like next(). You get the full reactive state machine (isLoading, data, error, status) plus page and totalPages atoms.
The async function receives no arguments — read fetchPosts.page.val (the non-reactive snapshot) inside the fn to build the request URL without registering the page atom as a reactive dependency. Set totalPages from the response so Prev/Next buttons can disable at the boundaries.
vs asyncAction
|
Capability
|
asyncAction
|
paginatedAsyncAction
|
|---|---|---|
| Reactive state machine | data / isLoading / error / status | Same atoms, same semantics. |
| Page cursor | — |
.page() atom (starts at 1) + writable .page.set().
|
| Total pages | — |
.totalPages() — set inside fn from the API response.
|
| Next helper | — |
.next() increments page and re-fetches in one call.
|
paginatedAsyncAction — jsonplaceholder users
Reads fetchUsers.page.val inside the fn, sets totalPages from X-Total-Count, and wires abortController. next() advances; Prev uses page.set then a call. next() is a no-op on the last page.