// page.tsx
const LIMIT = 10;
async function fetchItems(page: number) {
const items = prisma.item.findMany(...);
const itemsCount = prisma.item.count();
const pagesCount = Math.ceil(itemsCount / LIMIT);
const hasNextPage = page < pagesCount - 1;
const hasPreviousPage = page > 0;
return { items, hasNextPage, hasPreviousPage };
}
export default async function Page({searchParams}) {
const pageParam = searchParams.page;
const page = pageParam ? parseInt(pageParam) : 0;
const { items, hasNextPage, hasPreviousPage } = await fetchItems(page);
return (
<>
<Table ... />
{/* disable links when there's no page */}
<Link href={`/...?page=${page - 1}`}>Previous</Link>
<Link href={`/...?page=${page + 1}`}>Next</Link>
</>
)
}
// page.tsx
const LIMIT = 10;
async function fetchItems(page: number) {
const items = prisma.item.findMany(...);
const itemsCount = prisma.item.count();
const pagesCount = Math.ceil(itemsCount / LIMIT);
const hasNextPage = page < pagesCount - 1;
const hasPreviousPage = page > 0;
return { items, hasNextPage, hasPreviousPage };
}
export default async function Page({searchParams}) {
const pageParam = searchParams.page;
const page = pageParam ? parseInt(pageParam) : 0;
const { items, hasNextPage, hasPreviousPage } = await fetchItems(page);
return (
<>
<Table ... />
{/* disable links when there's no page */}
<Link href={`/...?page=${page - 1}`}>Previous</Link>
<Link href={`/...?page=${page + 1}`}>Next</Link>
</>
)
}