I built a very simple react pagination library with TypeScript.
react-awesome-paginate
React awesome paginate is a modern, lightweight, typescript based pagination component. You can use it in your project very easily. There are some predefined theme you can use it, in your component.
Install react-awesome-paginate with npm:
npm i react-awesome-paginate --save
Props & Theme demo: Codesandbox
API demo: Codesandbox
import Pagination from 'react-awesome-paginate'; // Import npm module
import 'react-awesome-paginate/dist/index.css'; // Import CSS (You can override css styling easily.)
// In your page
<Pagination
currentPage=1
totalPages=20
onPageChange={(pageNo: number) => console.log(pageNo)}
/>
import React, { useState } from "React";
import Pagination from 'react-awesome-paginate';
// For CSS Styling, you have to import this below file (You can override, if you want.)
import 'react-awesome-paginate/dist/index.css';
const ExampleComponent = () => {
const [currentPage, setCurrentPage] = useState(1);
const [totalPages, setTotalPages] = useState(1);
const handlePageChange = (pageNo) => {
if(pageNo === currentPage)
return;
// API Call && Set current page
}
return (
<Pagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={(pageNo: number) => handlePageChange(pageNo)}
/>
)
}
export default ExampleComponent;
| Name | Type | Status | Description |
|---|---|---|---|
onPageChange | Function | Required | onPageChange is a Function. When event is triggerd, it gives triggered page no. as an argument. |
| Name | Type | Status | Description |
|---|---|---|---|
currentPage | Number | Required | currentPage number. Default value 1 |
totalPages | Number | Required | totalPages number. Default value 1 |
previousLabel | String | Optional | previousLabel for previous button. Default value Previous |
nextLabel | String | Optional | nextLabel for next button. Default value Next |
morePagesLabel | String | Optional | morePagesLabel for break level. Default value ... |
paginationTheme | String | Optional | paginationTheme for next button. Default value default. There are four types of theme, you can use, these are default, circular, classic, compact |
activeClassName | String | Optional | activeClassName for active button. Default value active. You can add your own custom class & give custom style in your component |
containerClassName | String | Optional | containerClassName for active button. Default value None. You can add your own custom container class & give custom style in your component |
prevClassName | String | Optional | prevClassName for active button. Default value None. You can add your own custom class & give custom style to previous button in your component |
nextClassName | String | Optional | nextClassName for active button. Default value None. You can add your own custom class & give custom style to next button in your component |
If you like this package please give me a star(*) in my Github Repo
If you find any issue please please report here Github Issues




Building a reusable pagination component is a practical way to improve the usability of React applications that display large lists of records. This example shows how a lightweight component with customizable themes and page-change callbacks can make navigation easier while keeping the interface consistent. Using TypeScript also helps make component properties and event handlers more explicit, which is useful when maintaining a reusable library.
ReplyDeleteFor developers who want to implement similar features in real applications, ReactJS Course can help build a stronger understanding of component design, state management, and reusable UI elements. Pagination is particularly useful in dashboards, product listings, search results, and data-heavy applications where loading every record on one page would be inconvenient.
TypeScript adds another useful layer by defining types for properties such as the current page, total page count, and page-change callback. Exploring TypeScript Training can help developers create more predictable components and catch common mistakes during development, especially when publishing reusable packages for other projects to consume.
ReplyDelete