Skip to main content

usePageInfo

This hook provides helpful information about the current page and section information and gives access to the previous section's total page number to create custom pagination over the document.

The usePageInfo hook can be use in any level of JSX hierarchy as long as it is indirect/direct child of one of the Page... components like PageHeader or PageContent.

caution

using the usePageInfo hook in the children components of PageContent can cause unexpected behavior due to ComponentSnapshot. It is suggested to use this hook in a separate component with a minimal render element that is not subject to breaking/splitting between pages.

if you need to render the page number in the PageContent consider setting a static width for the component as a reserved space and avoid changing the page width of the page.

const {
pageNumber,
totalPages,
pageDimension,
pageMargin,
getSectionTotalPages,
getPreviousSectionTotalPages,
} = usePageInfo();
NameTypeDescription
pageNumbernumberstart from one
totalPagesnumbertotal page number in the current section
pageDimensionPageMarginIt can be different from what you passed to Section component
pageMarginPageDimensionIt can be different from what you passed to Section component
getSectionTotalPages(sectionId: number) => numberfunction take the section id and return total page number on that section,
getPreviousSectionTotalPages(backwardIndex: number) => numbertake a number like n and return the total page number of the nth previous section.