Skip to content

Commit

Permalink
perf(useQuery): don't cache promise when not set cacheKey
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Oct 21, 2024
1 parent 3497c4b commit 9e0d513
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/react-use/src/use-query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export function useQuery<T extends AnyFunc, D = Awaited<ReturnType<T>>, E = any>

const service = useLoadingSlowFn<T, D, E>(
useRetryFn<T, E>(
((...args) => {
((...args: Parameters<T>) => {
if (!cacheActions.isCacheEnabled) return latest.current.fetcher(...args)
const prePromise = cacheActions.getPromiseCache()
if (prePromise) return prePromise
const promise = latest.current.fetcher(...args)
Expand Down Expand Up @@ -305,7 +306,7 @@ export function useQuery<T extends AnyFunc, D = Awaited<ReturnType<T>>, E = any>

const refreshWithCache = useStableFn(async (params?: Parameters<T> | []) => {
const outerParams = cacheActions.isCacheEnabled ? latest.current.cache.params : service.params
const actualParams = params ?? (outerParams || [])
const actualParams = params ?? outerParams
return latest.current.enableRateControl ? refreshWithRateControl(actualParams) : service.refresh(actualParams)
})

Expand Down

0 comments on commit 9e0d513

Please sign in to comment.