-
-
Save vagnerlandio/be0a85c12ea61d292e1ff453e576f6a5 to your computer and use it in GitHub Desktop.
marvel api paginação
This file contains hidden or 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
const response = await axios.get( | |
`http://gateway.marvel.com/v1/public/comics?ts=${timeStamp}&apikey=${apiKey}&hash=${md5}&limit=20&offset=${ | |
(page - 1) * 20 | |
}` | |
); |
This file contains hidden or 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
<Pagination style={{ display: "flex", justifyContent: "center" }}> | |
<Pagination.First onClick={() => setPage(1)} /> | |
{page > 0 && <Pagination.Prev onClick={() => setPage(page - 1)} />} | |
{page > 2 && <Pagination.Ellipsis />} | |
{page > 2 && ( | |
<Pagination.Item onClick={() => setPage(page - 2)}> | |
{page - 2} | |
</Pagination.Item> | |
)} | |
{page > 1 && ( | |
<Pagination.Item onClick={() => setPage(page - 1)}> | |
{page - 1} | |
</Pagination.Item> | |
)} | |
<Pagination.Item active onClick={() => setPage(page)}> | |
{page} | |
</Pagination.Item> | |
{page < Math.ceil(total / 20) && ( | |
<Pagination.Item onClick={() => setPage(page + 1)}> | |
{page + 1} | |
</Pagination.Item> | |
)} | |
{page < Math.ceil(total / 20) - 1 && ( | |
<Pagination.Item onClick={() => setPage(page + 2)}> | |
{page + 2} | |
</Pagination.Item> | |
)} | |
<Pagination.Ellipsis /> | |
{page <= total / 20 && ( | |
<Pagination.Next onClick={() => setPage(page + 1)} /> | |
)} | |
{total / 20 > 5 && page < total / 20 && ( | |
<Pagination.Last | |
onClick={() => { | |
setPage(Math.ceil(total / 20)); | |
}} | |
/> | |
)} | |
</Pagination> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment