From 0a8b87c0991d68b9b525af9956cc29da23367a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=BD=E9=BE=99?= Date: Tue, 21 Dec 2021 14:01:22 +0800 Subject: [PATCH] fix: useRequest staleTime=-1 default loading=false --- packages/hooks/src/useRequest/src/plugins/useCachePlugin.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/hooks/src/useRequest/src/plugins/useCachePlugin.ts b/packages/hooks/src/useRequest/src/plugins/useCachePlugin.ts index b1b004d847..64380e7b68 100644 --- a/packages/hooks/src/useRequest/src/plugins/useCachePlugin.ts +++ b/packages/hooks/src/useRequest/src/plugins/useCachePlugin.ts @@ -47,6 +47,9 @@ const useCachePlugin: Plugin = ( if (cacheData && Object.hasOwnProperty.call(cacheData, 'data')) { fetchInstance.state.data = cacheData.data; fetchInstance.state.params = cacheData.params; + if (staleTime === -1 || new Date().getTime() - cacheData.time <= staleTime) { + fetchInstance.state.loading = false; + } } // subscribe same cachekey update, trigger update