@@ -15,7 +15,7 @@ const fetchPeople = async (key, pageIndex) => {
15
15
16
16
const PeopleTable = ( { columns } ) => {
17
17
const [ pageIndex , setPageIndex ] = useState ( 0 )
18
- const { data : peopleList , isLoading } = useQuery (
18
+ const { data : peopleList , isLoading, refetch , isFetching } = useQuery (
19
19
[ 'fetchPeople' , pageIndex ] ,
20
20
fetchPeople ,
21
21
)
@@ -47,8 +47,14 @@ const PeopleTable = ({ columns }) => {
47
47
return false
48
48
}
49
49
50
+ const handleRefetch = ( ) => {
51
+ setPageIndex ( 0 )
52
+ refetch ( )
53
+ }
54
+ console . log ( { isLoading, isFetching} )
50
55
return (
51
56
< div className = 'people-table' >
57
+ < div className = 'refetch-test' onClick = { ( ) => handleRefetch ( ) } > Refetch testing</ div >
52
58
< table { ...getTableProps ( ) } >
53
59
< thead >
54
60
{ headerGroups . map ( ( headerGroup , headerIndex ) => (
@@ -70,7 +76,7 @@ const PeopleTable = ({ columns }) => {
70
76
) ) }
71
77
</ thead >
72
78
< tbody { ...getTableBodyProps ( ) } >
73
- { ! isLoading &&
79
+ { ( ! isLoading || ! isFetching ) &&
74
80
page . map ( ( row , rowIndex ) => {
75
81
prepareRow ( row )
76
82
return (
@@ -87,7 +93,7 @@ const PeopleTable = ({ columns }) => {
87
93
} ) }
88
94
</ tbody >
89
95
</ table >
90
- { ! isLoading && (
96
+ { ( ! isLoading || ! isFetching ) && (
91
97
< div className = 'pagination' >
92
98
< button
93
99
disabled = { previousPagePossible ( ) }
@@ -109,10 +115,10 @@ const PeopleTable = ({ columns }) => {
109
115
</ span >
110
116
</ div >
111
117
) }
112
- { isLoading && < Skeleton
118
+ { ( isLoading || isFetching ) && < Skeleton
113
119
count = { 10 } height = { 50 }
114
120
width = { '100%' }
115
- /> }
121
+ /> }
116
122
</ div >
117
123
)
118
124
}
0 commit comments