1
1
import axios from 'axios' ;
2
- import { useState , useEffect } from 'react' ;
2
+ import { useState , useEffect , useCallback } from 'react' ;
3
3
import Card from '../components/Card' ;
4
4
import { useHistory } from 'react-router' ;
5
5
import LoadingSpinner from '../components/LoadingSpinner' ;
@@ -17,7 +17,7 @@ const BlogList = ({ isAdmin }) => {
17
17
const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
18
18
const [ numberOfPosts , setNumberOfPosts ] = useState ( 0 ) ;
19
19
const [ numberOfPages , setNumberOfPages ] = useState ( 0 ) ;
20
- const limit = 1 ;
20
+ const limit = 5 ;
21
21
22
22
useEffect ( ( ) => {
23
23
setNumberOfPages ( Math . ceil ( numberOfPosts / limit ) ) ;
@@ -26,7 +26,8 @@ const BlogList = ({ isAdmin }) => {
26
26
const onClickPageButton = ( page ) => {
27
27
history . push ( `${ location . pathname } ?page=${ page } ` )
28
28
}
29
- const getPosts = ( page = 1 ) => {
29
+
30
+ const getPosts = useCallback ( ( page = 1 ) => {
30
31
let params = {
31
32
_page : page ,
32
33
_limit : limit ,
@@ -45,12 +46,12 @@ const BlogList = ({ isAdmin }) => {
45
46
setPosts ( res . data ) ;
46
47
setLoading ( false ) ;
47
48
} )
48
- }
49
+ } , [ isAdmin ] )
49
50
50
51
useEffect ( ( ) => {
51
52
setCurrentPage ( parseInt ( pageParam ) || 1 ) ;
52
53
getPosts ( parseInt ( pageParam ) || 1 ) ;
53
- } , [ pageParam ] ) ;
54
+ } , [ pageParam , getPosts ] ) ;
54
55
55
56
const deleteBlog = ( e , id ) => {
56
57
e . stopPropagation ( ) ;
0 commit comments