Skip to content

Commit f167385

Browse files
committed
fix: 修复重置 loadingDelay 为 undefined 后,定时器没有被清理而导致 loading 始终为 true 的 bug
1 parent c7bb04c commit f167385

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/hooks/src/useRequest/src/plugins/useLoadingDelayPlugin.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ import type { Plugin, Timeout } from '../types';
44
const useLoadingDelayPlugin: Plugin<any, any[]> = (fetchInstance, { loadingDelay, ready }) => {
55
const timerRef = useRef<Timeout>();
66

7-
if (!loadingDelay) {
8-
return {};
9-
}
10-
117
const cancelTimeout = () => {
128
if (timerRef.current) {
139
clearTimeout(timerRef.current);
1410
}
1511
};
1612

13+
if (!loadingDelay) {
14+
return {
15+
onFinally: () => {
16+
cancelTimeout();
17+
},
18+
onCancel: () => {
19+
cancelTimeout();
20+
},
21+
};
22+
}
23+
1724
return {
1825
onBefore: () => {
1926
cancelTimeout();

0 commit comments

Comments
 (0)