Created
June 8, 2022 07:53
-
-
Save officialrajdeepsingh/22d697c38a58f594151b4bdd97a23d4d to your computer and use it in GitHub Desktop.
Pagination component in nextjs static blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react' | |
| import Link from "next/link"; | |
| import { useRouter } from "next/router"; | |
| function Pagnation({totalPostCount}) { | |
| let router = useRouter() | |
| /* | |
| pages give number,base on number we create a array. base on array we map a list elements | |
| totalPostCount = 3 | |
| conver into array [0,1,2] | |
| base on array create list in array | |
| */ | |
| let pageIntoArray = Array.from(Array(totalPostCount).keys()) | |
| return ( | |
| <nav aria-label=" my-6"> | |
| <ul className="pagination justify-content-center"> | |
| { | |
| pageIntoArray.map(page => { | |
| return <li key={page} className="page-item p-2"> | |
| <Link href={ page === 0 ? "/" : `/page/${page + 1}` }> | |
| <a className="page-link" >{page + 1} </a> | |
| </Link> | |
| </li> | |
| }) | |
| } | |
| </ul> | |
| </nav> | |
| ) | |
| } | |
| export default Pagnation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment