Skip to content

Instantly share code, notes, and snippets.

@officialrajdeepsingh
Created June 8, 2022 07:53
Show Gist options
  • Select an option

  • Save officialrajdeepsingh/22d697c38a58f594151b4bdd97a23d4d to your computer and use it in GitHub Desktop.

Select an option

Save officialrajdeepsingh/22d697c38a58f594151b4bdd97a23d4d to your computer and use it in GitHub Desktop.
Pagination component in nextjs static blog
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