From d45c1335d991580196639ba82f3ecf0e2c78b755 Mon Sep 17 00:00:00 2001 From: guaijie <30885718+guaijie@users.noreply.github.com> Date: Tue, 14 May 2024 19:51:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=87=8D=E7=BD=AE=20l?= =?UTF-8?q?oadingDelay=20=E4=B8=BA=20undefined=20=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8=E6=B2=A1=E6=9C=89=E8=A2=AB=E6=B8=85?= =?UTF-8?q?=E7=90=86=E8=80=8C=E5=AF=BC=E8=87=B4=20loading=20=E5=A7=8B?= =?UTF-8?q?=E7=BB=88=E4=B8=BA=20true=20=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/useLoadingDelayPlugin.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/hooks/src/useRequest/src/plugins/useLoadingDelayPlugin.ts b/packages/hooks/src/useRequest/src/plugins/useLoadingDelayPlugin.ts index 74e4fb6f14..2425d1eea4 100644 --- a/packages/hooks/src/useRequest/src/plugins/useLoadingDelayPlugin.ts +++ b/packages/hooks/src/useRequest/src/plugins/useLoadingDelayPlugin.ts @@ -4,16 +4,23 @@ import type { Plugin, Timeout } from '../types'; const useLoadingDelayPlugin: Plugin = (fetchInstance, { loadingDelay, ready }) => { const timerRef = useRef(); - if (!loadingDelay) { - return {}; - } - const cancelTimeout = () => { if (timerRef.current) { clearTimeout(timerRef.current); } }; + if (!loadingDelay) { + return { + onFinally: () => { + cancelTimeout(); + }, + onCancel: () => { + cancelTimeout(); + } + }; + } + return { onBefore: () => { cancelTimeout();