Skip to main content

Render pagination

The renderPagination prop can be used to render a component that receives pagination data.

Example

import type { RenderPagination } from './TileSlider';

export const renderPagination: RenderPagination = ({ page, pages, slideToPage }) => {
const items = Array.from({ length: props.pages }, (_, pageIndex) => pageIndex);

return (
<ul className="paginationDots">
{items.map((current) => (
<li key={current} className={page === current ? 'activeDot' : ''} onClick={() => slideToPage(current)}>
&#9679;
</li>
))}
</ul>
);
};

Props

The renderPagination function receives the following props:

NameTypeDescription
pagenumberThe current page index
pagesnumberThe number of pages
indexnumberThe current slide index
totalnumberThe total slides
slideToPage(page: number) => voidCallback to slide to the given page index
slideToIndex(index: number) => voidCallback to slide to the given tile index
slide(direction: 'left' | 'right') => voidCallback to slide left or right