Skip to content

Commit

Permalink
fix: param variables in enabled function
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoliao666 committed Apr 26, 2023
1 parent c37d3ed commit 0743f47
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/createBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
AdditionalQueryHookOptions,
Updater,
} from './types'
import { isUndefined } from './utils'

interface CreateQueryOptions
extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,
Expand Down Expand Up @@ -34,10 +35,10 @@ export function createBaseQuery(
const getPrimaryKey = () => primaryKey

const getKey = (variables?: any) =>
typeof variables === 'undefined' ? [primaryKey] : [primaryKey, variables]
isUndefined(variables) ? [primaryKey] : [primaryKey, variables]

const useGeneratedQuery = ({
variables,
variables: currVariables,
...currOptions
}: QueryBaseHookOptions = {}) => {
const {
Expand All @@ -49,7 +50,9 @@ export function createBaseQuery(
...useDefaultOptions?.(),
} as QueryBaseHookOptions

const queryKey = getKey(variables ?? prevVariables)
const variables = isUndefined(currVariables) ? prevVariables : currVariables

const queryKey = getKey(variables)

const { enabled, ...mergedOptions } = {
...prevOptions,
Expand Down
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isUndefined(value: any): value is undefined {
return typeof value === 'undefined'
}

0 comments on commit 0743f47

Please sign in to comment.