Skip to content

Instantly share code, notes, and snippets.

@vagnerlandio
Created January 7, 2022 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vagnerlandio/be0a85c12ea61d292e1ff453e576f6a5 to your computer and use it in GitHub Desktop.
Save vagnerlandio/be0a85c12ea61d292e1ff453e576f6a5 to your computer and use it in GitHub Desktop.
marvel api paginação
const response = await axios.get(
`http://gateway.marvel.com/v1/public/comics?ts=${timeStamp}&apikey=${apiKey}&hash=${md5}&limit=20&offset=${
(page - 1) * 20
}`
);
<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