1. Calculate several records.

  2. Ignore the previous records.

First : (pageNumber -1 )0* page size

0*6 = 0 // skip the first 0 records.

Second : (2-1)*6 = 6 records skipped.

Third : (3-1) *6 = 12 records skipped.

Data.find({}). limit(page size).skip(inject the above formula).

  1. Calculate a number of pages: math.ceil(total records / page size).

  2. Pass the total page as a prop to the pagination component.

  3. Pass the current page as a prop to the pagination component for highlighting the current page.

Previous and Next buttons :

Previous button : <Link href={/?page=${current page -1}} />

Next button : <Link href={/page=${current page + 1}} />