Skip to content

Instantly share code, notes, and snippets.

@Origho-precious
Created September 16, 2021 21:00
Show Gist options
  • Save Origho-precious/685527c280942c831734088554629725 to your computer and use it in GitHub Desktop.
Save Origho-precious/685527c280942c831734088554629725 to your computer and use it in GitHub Desktop.
Pagination Component - 2
useEffect(() => {
const paginationNums = () => {
const max = Math.floor(listLength / 50);
let nums = [];
for (let i = 0; i <= max; i++) {
nums.push(max - i);
}
setNumsArr(
nums.sort((a, b) => {
return a - b;
})
);
};
paginationNums();
}, [listLength]);
return (
<StyledPagination>
{numsArr?.length
? numsArr?.map((num) => (
<button
className={pageNum === num ? "active" : ""}
onClick={() => setPageNum(num)}
key={num}
>
{num + 1}
</button>
))
: null}
</StyledPagination>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment