diff --git a/packages/react-use/src/use-query/index.tsx b/packages/react-use/src/use-query/index.tsx index 57d59d6..6038f9b 100644 --- a/packages/react-use/src/use-query/index.tsx +++ b/packages/react-use/src/use-query/index.tsx @@ -189,10 +189,13 @@ export function useQuery>, E = any> ): UseQueryReturns { const [cache, cacheActions] = useQueryCache(options) - const latest = useLatest({ fetcher, cache, ...options }) const debounceOptions = isNumber(options.debounce) ? { wait: options.debounce } : options.debounce const throttleOptions = isNumber(options.throttle) ? { wait: options.throttle } : options.throttle + const enableRateControl = Boolean(debounceOptions || throttleOptions) + + const latest = useLatest({ fetcher, cache, enableRateControl, ...options }) + const service = useLoadingSlowFn( useRetryFn( ((...args) => { @@ -297,17 +300,17 @@ export function useQuery>, E = any> return service.mutate(nextData, nextParams) }) - const refreshWithCacheAndRateControl = useStableFn(async (params?: Parameters | []) => { + const refreshWithCache = useStableFn(async (params?: Parameters | []) => { const outerParams = cacheActions.isCacheEnabled ? latest.current.cache.params : service.params const actualParams = params ?? (outerParams || []) - return refreshWithRateControl(actualParams) + return latest.current.enableRateControl ? refreshWithRateControl(actualParams) : service.refresh(actualParams) }) return { ...pausable, mutate: mutateWithCache, - refresh: refreshWithCacheAndRateControl, - run: serviceWithRateControl, + refresh: refreshWithCache, + run: enableRateControl ? serviceWithRateControl : service.run, cancel: service.cancel, get params() { return cacheActions.isCacheEnabled ? cache.params : service.params