Skip to content

Commit 637fb9a

Browse files
committed
56
1 parent 810e5a1 commit 637fb9a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/components/BlogList.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ const BlogList = ({ isAdmin }) => {
1010
const history = useHistory();
1111
const [posts, setPosts] = useState([]);
1212
const [loading, setLoading] = useState(true);
13+
const [currentPage, setCurrentPage] = useState(1);
1314

1415
const getPosts = (page = 1) => {
16+
setCurrentPage(page);
1517
let params = {
1618
_page: page,
1719
_limit: 5,
@@ -76,7 +78,11 @@ const BlogList = ({ isAdmin }) => {
7678
return (
7779
<div>
7880
{renderBlogList()}
79-
<Pagination currentPage={3} numberOfPages={3} />
81+
<Pagination
82+
currentPage={currentPage}
83+
numberOfPages={3}
84+
onClick={getPosts}
85+
/>
8086
</div>
8187
)
8288
};

src/components/Pagination.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import propTypes from "prop-types";
22

3-
const Pagination = ({ currentPage, numberOfPages }) => {
3+
const Pagination = ({ currentPage, numberOfPages, onClick }) => {
44
return (
55
<nav aria-label="Page navigation example">
66
<ul className="pagination justify-content-center">
@@ -15,7 +15,14 @@ const Pagination = ({ currentPage, numberOfPages }) => {
1515
key={pageNumber}
1616
className={`page-item ${currentPage === pageNumber ? 'active' : ''}`}
1717
>
18-
<a className="page-link" href="#">{pageNumber}</a>
18+
<div
19+
className="page-link cursor-pointer"
20+
onClick={() => {
21+
onClick(pageNumber);
22+
}}
23+
>
24+
{pageNumber}
25+
</div>
1926
</li>
2027
})}
2128
<li className="page-item">
@@ -30,7 +37,8 @@ const Pagination = ({ currentPage, numberOfPages }) => {
3037

3138
Pagination.propTypes = {
3239
currentPage: propTypes.number,
33-
numberOfPages: propTypes.number
40+
numberOfPages: propTypes.number.isRequired,
41+
onClick: propTypes.func.isRequired
3442
}
3543

3644
Pagination.defaultProps = {

0 commit comments

Comments
 (0)