DEV Community

Discussion on: Implementing Pagination feature in Vanilla JS

Collapse
 
lakbychance profile image
Lakshya Thakur

Hey thanks for the feedback. I didn't quite get the functional approach. Can you elaborate a bit more for my benefit ?

Collapse
 
lexlohr profile image
Alex Lohr

Without providing a fully working example, instead of having a Pagination object, you merely use a pure function (same input always produces same output) to calculate the pagination that should be displayed:

const getPagination = (currentPage, pages, showPages) => {
  const pagination = []; // ...do the calculation
  return pagination;
};
Enter fullscreen mode Exit fullscreen mode