Skip to Content
Core SDKPaginação

Pagination

Como paginar resultados no Meaple SDK.

Parâmetros de Paginação

A maioria das APIs que retornam listas suportam paginação:

const { events, total } = await sdk.events.find({ limit: 20, // Itens por página offset: 0, // Índice inicial });

Exemplo Completo

import { MeapleSDK } from '@meaple-com/core'; const sdk = new MeapleSDK({ publicKey: 'pk_seu_channel_id', }); async function loadEvents(page: number = 1, pageSize: number = 20) { const { events, total } = await sdk.events.find({ limit: pageSize, offset: (page - 1) * pageSize, }); return { events, total, totalPages: Math.ceil(total / pageSize), currentPage: page, }; } // Usar const page1 = await loadEvents(1, 20); const page2 = await loadEvents(2, 20);

Com React Query

import { useEvents } from '@meaple-com/react-query'; function EventsList({ page }: { page: number }) { const { data, isLoading } = useEvents({ limit: 20, offset: (page - 1) * 20, }); if (isLoading) return <div>Carregando...</div>; return ( <div> <p>Total: {data?.total} eventos</p> {data?.events.map(event => ( <div key={event.id}>{event.name}</div> ))} </div> ); }

Cursor-based Pagination

Algumas APIs usam cursor ao invés de offset:

const { categories, cursor } = await sdk.categories.find({ limit: 20, cursor: 'next-page-cursor', });

Próximos Passos

Last updated on