Skip to content

Commit ff8d5b8

Browse files
committed
60
1 parent 3115225 commit ff8d5b8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/components/BlogList.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from 'axios';
2-
import { useState, useEffect } from 'react';
2+
import { useState, useEffect, useCallback } from 'react';
33
import Card from '../components/Card';
44
import { useHistory } from 'react-router';
55
import LoadingSpinner from '../components/LoadingSpinner';
@@ -17,7 +17,7 @@ const BlogList = ({ isAdmin }) => {
1717
const [currentPage, setCurrentPage] = useState(1);
1818
const [numberOfPosts, setNumberOfPosts] = useState(0);
1919
const [numberOfPages, setNumberOfPages] = useState(0);
20-
const limit = 1;
20+
const limit = 5;
2121

2222
useEffect(() => {
2323
setNumberOfPages(Math.ceil(numberOfPosts/limit));
@@ -26,7 +26,8 @@ const BlogList = ({ isAdmin }) => {
2626
const onClickPageButton = (page) => {
2727
history.push(`${location.pathname}?page=${page}`)
2828
}
29-
const getPosts = (page = 1) => {
29+
30+
const getPosts = useCallback((page = 1) => {
3031
let params = {
3132
_page: page,
3233
_limit: limit,
@@ -45,12 +46,12 @@ const BlogList = ({ isAdmin }) => {
4546
setPosts(res.data);
4647
setLoading(false);
4748
})
48-
}
49+
}, [isAdmin])
4950

5051
useEffect(() => {
5152
setCurrentPage(parseInt(pageParam) || 1);
5253
getPosts(parseInt(pageParam) || 1);
53-
}, [pageParam]);
54+
}, [pageParam, getPosts]);
5455

5556
const deleteBlog = (e, id) => {
5657
e.stopPropagation();

0 commit comments

Comments
 (0)