subscribeWithPagination
subscribeWithPagination
is a special type of subscription that is used to fetch data in pages. It is similar to subscribe
but it has a few differences:
- It expects the query to have a
limit
defined. - It returns
nextPage
andprevPage
functions to fetch the next and previous pages of data. - The subscription callback will have
hasNextPage
andhasPreviousPage
booleans to indicate if there are more pages to fetch.
const { unsubscribe, nextPage, prevPage } = client.subscribeWithPagination(
query,
(results, { hasRemoteFulfilled, hasNextPage, hasPreviousPage }) => {
// handle results
},
(error) => {
// handle error
},
// Optional
{
localOnly: false,
onRemoteFulfilled: () => {
console.log('server has sent back results for the subscription');
},
}
);