Skip to content

Function: paginate() ​

ts
function paginate<T>(fetchPage): AsyncGenerator<T>;

Walks every page of a cursor-paginated endpoint, yielding items one by one. fetchPage takes the cursor (undefined for the first page) and returns a Page. Iteration stops when a page has no nextCursor.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterType
fetchPage(cursor?) => Promise<Page<T>>

Returns ​

AsyncGenerator<T>

MIT License. Not affiliated with, endorsed or sponsored by Meta or Instagram.