Skip to content

Commit 0ef680c

Browse files
authored
revert(0d1e1ad): avoid continuous loading on 401 status (#475)
This reverts commit 0d1e1ad.
1 parent 2e0acf9 commit 0ef680c

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/hooks/useFetch.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ export const useLoading = <T>(
1111
loading,
1212
async (...arg: any[]) => {
1313
setLoading(true)
14-
try {
15-
return await p(...arg)
16-
} finally {
14+
const data = await p(...arg)
15+
if (!fetch || (data as EmptyResp).code !== 401) {
16+
// why?
17+
// because if setLoading(false) here will rerender before navigate
18+
// maybe cause some bugs
1719
setLoading(false)
1820
}
21+
return data
1922
},
2023
]
2124
}
@@ -37,11 +40,11 @@ const useListLoading = <T, K>(
3740
loading,
3841
async (key: K, ...arg: any[]) => {
3942
setLoading(() => key)
40-
try {
41-
return await p(key, ...arg)
42-
} finally {
43+
const data = await p(key, ...arg)
44+
if (!fetch || (data as EmptyResp).code !== 401) {
4345
setLoading(undefined)
4446
}
47+
return data
4548
},
4649
]
4750
}

0 commit comments

Comments
 (0)