Skip to content

Commit 01d39fa

Browse files
committed
Testing out manual refetch.
1 parent afb73ab commit 01d39fa

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/components/ReactTable.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,15 @@ table > tbody > tr {
3333
.pagination > button:disabled {
3434
cursor: not-allowed;
3535
}
36+
.refetch-test {
37+
display: flex;
38+
width: 150px;
39+
font-weight: 600;
40+
background: #b6cdff;
41+
height: 40px;
42+
justify-content: center;
43+
align-items: center;
44+
margin: 0 0 10px 0;
45+
cursor: pointer;
46+
border-radius: 6px;
47+
}

src/components/ReactTable.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const fetchPeople = async (key, pageIndex) => {
1515

1616
const PeopleTable = ({ columns }) => {
1717
const [pageIndex, setPageIndex] = useState(0)
18-
const { data: peopleList, isLoading } = useQuery(
18+
const { data: peopleList, isLoading, refetch, isFetching } = useQuery(
1919
['fetchPeople', pageIndex],
2020
fetchPeople,
2121
)
@@ -47,8 +47,14 @@ const PeopleTable = ({ columns }) => {
4747
return false
4848
}
4949

50+
const handleRefetch = () => {
51+
setPageIndex(0)
52+
refetch()
53+
}
54+
console.log({isLoading, isFetching})
5055
return (
5156
<div className = 'people-table'>
57+
<div className = 'refetch-test' onClick = { () => handleRefetch() }>Refetch testing</div>
5258
<table { ...getTableProps() }>
5359
<thead>
5460
{headerGroups.map((headerGroup, headerIndex) => (
@@ -70,7 +76,7 @@ const PeopleTable = ({ columns }) => {
7076
))}
7177
</thead>
7278
<tbody { ...getTableBodyProps() }>
73-
{!isLoading &&
79+
{(!isLoading || !isFetching ) &&
7480
page.map((row, rowIndex) => {
7581
prepareRow(row)
7682
return (
@@ -87,7 +93,7 @@ const PeopleTable = ({ columns }) => {
8793
})}
8894
</tbody>
8995
</table>
90-
{!isLoading && (
96+
{(!isLoading || !isFetching) && (
9197
<div className = 'pagination'>
9298
<button
9399
disabled = { previousPagePossible() }
@@ -109,10 +115,10 @@ const PeopleTable = ({ columns }) => {
109115
</span>
110116
</div>
111117
)}
112-
{isLoading && <Skeleton
118+
{(isLoading || isFetching) && <Skeleton
113119
count = { 10 } height = { 50 }
114120
width = { '100%' }
115-
/>}
121+
/>}
116122
</div>
117123
)
118124
}

0 commit comments

Comments
 (0)