Skip to content

Commit

Permalink
fix(useQuery): fix global mutate params error
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Aug 20, 2024
1 parent 357e77a commit 3d35a3b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/use-query/use-query-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function createMutate(dataCache: UseQueryCacheLike<unknown>, paramsCache: Map<st
return (
keyFilter: Arrayable<string> | ((key: string) => boolean),
value: SetStateAction<unknown> = undefined,
params: unknown[] = [],
params: SetStateAction<unknown[]> = [],
) => {
const keys = isFunction(keyFilter)
? Array.from(dataCache.keys()).filter(keyFilter)
Expand All @@ -149,9 +149,12 @@ function createMutate(dataCache: UseQueryCacheLike<unknown>, paramsCache: Map<st
const prevData = dataCache.get(key)
const nextData = isFunction(value) ? value(prevData) : value

const prevParams = paramsCache.get(key) ?? []
const nextParams = isFunction(params) ? params(prevParams) : params

if (isDefined(key)) {
dataCache.set(key, nextData)
paramsCache.set(key, params)
paramsCache.set(key, nextParams)
} else {
dataCache.delete(key)
paramsCache.delete(key)
Expand Down

0 comments on commit 3d35a3b

Please sign in to comment.