
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
nextjs-pagination
Advanced tools
A highly customizable pagination component for Next.js applications. It provides flexible configuration options for page navigation and improves user experience in large scale data environments.
Nextjs-Pagination is a powerful, customizable, and easy-to-use pagination component built specifically for Next.js projects. Designed with user experience in mind, it provides flexible configuration options so you can adjust the pagination behavior and look-and-feel to suit your needs. Nextjs-Pagination is built with TypeScript, offering type safety and autocompletion support in supported editors.
color="green"
and shape="circle"
as props.buttonCount={7}
as a prop.showNextPrev={true}
as a prop.showFirstLast={true}
as a prop.onPageChange
prop.firstText="Start"
, prevText="Backward"
, nextText="Forward"
, lastText="End"
firstText="⏮"
, prevText="⏪"
, nextText="⏩"
, lastText="⏭"
firstText="⇤"
, prevText="←"
, nextText="→"
, lastText="⇥"
firstText="⟪"
, prevText="⟨"
, nextText="⟩"
, lastText="⟫"
"pagination-container"
and "pagination-button"
to the pagination container and buttons respectively, pass className="pagination-container"
and buttonClassName="pagination-button"
as props. Remember to replace these with your own CSS classes.Install the package using npm:
npm install nextjs-pagination
npm install nextjs-pagination
First, import the Pagination component from the nextjs-pagination
package then use it in your components. Below are the 3 required props needed for JavaScript and TypeScript components:
import { Pagination } from 'nextjs-pagination';
const TSExample = () => {
const handlePageChange = (page: number) => {
setCurrentPage(page);
};
return (
<Pagination
onPageChange={handlePageChange}
totalItems={100}
itemsPerPage={10}
/>
);
};
import Pagination from 'nextjs-pagination';
const JSExample = () => {
const handlePageChange = (page) => {
setCurrentPage(page);
};
return (
<Pagination
onPageChange={handlePageChange}
totalItems={100}
itemsPerPage={10}
/>
);
};
This will render a pagination component for 100 items with 10 items per page.
Below are the props that you can pass to the Pagination component:
Prop | Description | Type | Default | Required |
---|---|---|---|---|
totalItems | Total number of items | number | - | Yes |
itemsPerPage | Number of items per page | number | - | Yes |
onPageChange | Callback function called when page changes | function | () => {} | Yes |
color | Button color | string | '#007bff' | No |
shape | Button shape ('circle' or 'square') | string | 'square' | No |
buttonCount | Maximum number of page buttons | number | 5 | No |
showNextPrev | Whether to show 'Next' and 'Prev' buttons | boolean | false | No |
showFirstLast | Whether to show 'First' and 'Last' buttons | boolean | false | No |
onSuccess | Callback function called when a valid page is selected | function | () => {} | No |
onError | Callback function called when an error occurs | function | () => {} | No |
customStyles | Custom styles for the buttons. You can use this to apply CSS-in-JS styles directly to the buttons. | React.CSSProperties | {} | No |
firstText | Text for the 'First' button. Can be any valid React node, such as text, emojis, symbols, etc. | React.ReactNode | 'First' | No |
prevText | Text for the 'Prev' button. Can be any valid React node, such as text, emojis, symbols, etc. | React.ReactNode | 'Prev' | No |
nextText | Text for the 'Next' button. Can be any valid React node, such as text, emojis, symbols, etc. | React.ReactNode | 'Next' | No |
lastText | Text for the 'Last' button. Can be any valid React node, such as text, emojis, symbols, etc. | React.ReactNode | 'Last' | No |
className | Custom CSS class name for the pagination container. You should replace this with your own CSS class name. | string | '' | No |
buttonClassName | Custom CSS class name for the buttons. You should replace this with your own CSS class name. | string | '' | No |
@types/
nextjs-pagination.d.ts
- TypeScript declaration file for the package.dist/
index.js
- Compiled JavaScript file of the package.Pagination.js
- Compiled JavaScript file of the package.src/
index.ts
- Entry point file of the package.Pagination.tsx
- The main implementation of the pagination component..babelrc
- Babel configuration file.jest.config.js
- Jest configuration file.package.json
- Package metadata and dependency information.tsconfig.json
- TypeScript configuration file.Want to see it in action? CLICK HERE! to check our the example on replit.
(please give it a few seconds to start up the server when you load)
import { Pagination } from 'nextjs-pagination';
const ExamplePage: React.FC = () => {
const handlePageChange = (page: number) => {
setCurrentPage(page);
};
return (
<Pagination
totalItems={500}
itemsPerPage={20}
onPageChange={handlePageChange}
color="green"
shape="circle"
buttonCount={7}
showNextPrev={true}
showFirstLast={true}
onSuccess={(page: number) => console.log("Current page: ", page)}
onError={(error: Error) => console.error(error)}
firstText="First"
lastText="Last"
prevText="Prev"
nextText="Next"
className="custom-pagination-container-class"
buttonClassName="custom-pagination-button-class"
/>
);
};
import Pagination from 'nextjs-pagination';
const ExamplePage = () => {
const handlePageChange = (page) => {
setCurrentPage(page);
};
return (
<Pagination
totalItems={500}
itemsPerPage={20}
onPageChange={handlePageChange}
color="green"
shape="circle"
buttonCount={7}
showNextPrev={true}
showFirstLast={true}
onSuccess={(page) => console.log("Current page: ", page)}
onError={(error) => console.error(error)}
firstText="First"
lastText="Last"
prevText="Prev"
nextText="Next"
className="custom-pagination-container-class"
buttonClassName="custom-pagination-button-class"
/>
);
};
We welcome contributions! Whether it's a bug report, feature request, or a code contribution, we greatly appreciate all help to improve Nextjs-Pagination. For major changes, please open an issue first to discuss what you would like to change.
Nextjs-Pagination is MIT licensed.
FAQs
A highly customizable pagination component for Next.js applications. It provides flexible configuration options for page navigation and improves user experience in large scale data environments.
The npm package nextjs-pagination receives a total of 8 weekly downloads. As such, nextjs-pagination popularity was classified as not popular.
We found that nextjs-pagination demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.