import { paginate } from "https://deno.land/x/netzo@0.4.42/integrations/create-api/pagination/mod.ts";
Paginate over a fetchPage function
Examples
const fetchPage = async (options: PaginationOptions) => {
const { limit, cursor } = options;
const response = await fetch(/api/users?limit=${limit}&cursor=${cursor}
);
const data = await response.json();
return {
data,
nextCursor: data.length === limit ? encodeCursorCursor(data[data.length - 1].id) : undefined,
};
};
const { data, nextCursor, previousCursor } = await paginate(fetchPage, { limit: 50 });
console.log(data, nextCursor, previousCursor);
const fetchPage = async (options: PaginationOptions) => {
const { limit, cursor } = options;
const response = await fetch(/api/users?limit=${limit}&cursor=${cursor}
);
const data = await response.json();
return {
data,
nextCursor: data.length === limit ? encodeCursorCursor(data[data.length - 1].id) : undefined,
};
};
const { data, nextCursor, previousCursor } = await paginate(fetchPage, { limit: 50 });
console.log(data, nextCursor, previousCursor);
Parameters
fetchPage: (options: PaginationOptions) => Promise<PaginationResult<T>>
options: PaginationOptions
Returns
Promise<PaginationResult<T>>