Created
September 16, 2021 21:00
-
-
Save Origho-precious/685527c280942c831734088554629725 to your computer and use it in GitHub Desktop.
Pagination Component - 2
This file contains 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
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