From 0743f47a37e1b82dadeb6c1a9f4a7af7e6e2d96a Mon Sep 17 00:00:00 2001 From: liaoliao666 Date: Wed, 26 Apr 2023 10:21:33 +0800 Subject: [PATCH] fix: param variables in enabled function --- src/createBaseQuery.ts | 9 ++++++--- src/utils.ts | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 src/utils.ts diff --git a/src/createBaseQuery.ts b/src/createBaseQuery.ts index ca7acca..744e1c2 100644 --- a/src/createBaseQuery.ts +++ b/src/createBaseQuery.ts @@ -5,6 +5,7 @@ import type { AdditionalQueryHookOptions, Updater, } from './types' +import { isUndefined } from './utils' interface CreateQueryOptions extends Omit, @@ -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 { @@ -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, diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..65fa9ce --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,3 @@ +export function isUndefined(value: any): value is undefined { + return typeof value === 'undefined' +}