-
-
Save codebucks27/9f7e3c06d5cb2a68a700c777f674cff6 to your computer and use it in GitHub Desktop.
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
import React, { useEffect, useState } from "react"; | |
import "./style.css"; | |
const renderData = (data) => { | |
return ( | |
<ul> | |
{data.map((todo, index) => { | |
return <li key={index}>{todo.title}</li>; | |
})} | |
</ul> | |
); | |
}; | |
function PaginationComponent() { | |
const [data, setData] = useState([]); | |
useEffect(() => { | |
fetch("https://jsonplaceholder.typicode.com/todos") | |
.then((response) => response.json()) | |
.then((json) => setData(json)); | |
}, []); | |
const handleClick = (event) => { | |
setcurrentPage(Number(event.target.id)); | |
}; | |
const renderPageNumbers = pages.map((number) => { | |
return ( | |
<li | |
key={number} | |
id={number} | |
onClick={handleClick} | |
className={currentPage == number ? "active" : null} | |
> | |
{number} | |
</li> | |
); | |
}); | |
return ( | |
<> | |
<h1>Todo List</h1> <br /> | |
{renderData(data)} | |
<ul className="pageNumbers"> | |
{renderPageNumbers} | |
</ul> | |
</> | |
); | |
} | |
export default PaginationComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment