Pagination on Custom types

I'm trying to create pagination on custom types, trying to set limitations but I see that it limits not exactly my articles, here I add screenshots of my custom type and the data structure that I get from prismic


and here you can see how I fetch data with prismic client
const res = await client.getAllByType('articles', {limit:2})

I do not really understand how to limit the count of articles from data

Thank you

Hi Jakub,

It sounds like the API option you want might be pageSize, rather than limit. To the best of my knowledge, we don't have a limit option.

See the pageSize option, here:

You could try this:

const res = await client.getAllByType('articles', {pageSize:2})

Let me know if that helps.
Sam

If I may be so bold as to interject...

I believe the "get all" methods like getAllByType do not return a paginated list where the standard methods do like getByType. See an example I use for my blog index:
Documentation
I've included all but my structured data in case it helps:

import { Metadata } from 'next'
import { notFound } from 'next/navigation'
import { SliceZone } from '@prismicio/react'
import * as prismic from '@prismicio/client'
import { createClient } from '@/prismicio'
import { components } from '@/slices'
import { Graph } from 'schema-dts'
import Section from '@/components/Section'
import BlogCard from '@/components/BlogCard'
import Pagination from '@/components/Pagination'
export default async function Page({
  params,
  searchParams,
}: {
  params: Params
  searchParams: SearchParams
}) {
  const client = createClient()
  const pageNumber = Number(searchParams['page']) || 1
  const page = await client.getByUID('page', params.uid).catch(() => notFound())
  let posts
  if (page.uid === 'blog') {
    posts = await client.getByType('post', {
      orderings: {
        field: 'document.first_publication_date',
        direction: 'desc',
      },
      page: pageNumber,
      pageSize: 5,
    })
  }
  const settings = await client.getSingle('settings')
return (
    <>
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
      />
      <SliceZone slices={page.data.slices} components={components} />
      {/* CODE FOR BLOG PAGE ONLY */}
      {page.uid === 'blog' && (
        <Section width="md">
          {posts && posts.results.length > 0 ? (
            <ul className="px-4 lg:px-0">
              {posts.results.map(post => {
                return (
                  <BlogCard
                    key={post.id}
                    post={post}
                    className="mx-auto max-w-xl"
                  />
                )
              })}
            </ul>
          ) : (
            <p className="prose mx-auto lg:prose-lg xl:prose-xl">
              No posts have been published yet. Please check back again soon!
            </p>
          )}
          {(posts?.next_page !== null || posts?.prev_page !== null) && (
            <Pagination
              hasNextPage={posts?.next_page !== null}
              hasPrevPage={posts?.prev_page !== null}
              totalPages={Number(posts?.total_pages)}
            />
          )}
        </Section>
      )}
      {/* END BLOG PAGE CODE */}
    </>
  )
}

@nf_mastroianni You're completely correct! In this case, neither pageSize nor limit should have any effect whatsoever.

1 Like