From ba16dc2b935b62806ca0d95a33f1a8d6401e8145 Mon Sep 17 00:00:00 2001 From: liaoliao666 <1076988944@qq.com> Date: Fri, 13 Oct 2023 03:46:19 +0800 Subject: [PATCH] feat: remove automatically inspect primary key --- src/createBaseQuery.ts | 26 +++++++++----------------- src/utils.ts | 1 + 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/createBaseQuery.ts b/src/createBaseQuery.ts index 94a8e88..94d2249 100644 --- a/src/createBaseQuery.ts +++ b/src/createBaseQuery.ts @@ -21,29 +21,12 @@ type QueryBaseHookOptions = Omit< variables?: any } -const existedPrimaryKeys = new Set() - export const createBaseQuery = ( defaultOptions: any, useRQHook: (options: any, queryClient?: any) => any, overrideOptions?: QueryBaseHookOptions ): any => { - const { - primaryKey, - queryFn, - queryKeyHashFn, - getPreviousPageParam, - getNextPageParam, - initialPageParam, - } = defaultOptions as CreateBaseQueryOptions - if (process.env.NODE_ENV !== 'production') { - if (existedPrimaryKeys.has(primaryKey)) { - console.error(`[Bug] Duplicated primaryKey: ${primaryKey}`) - } else { - existedPrimaryKeys.add(primaryKey) - } - // @ts-ignore if (defaultOptions.useDefaultOptions) { console.error( @@ -52,6 +35,15 @@ export const createBaseQuery = ( } } + const { + primaryKey, + queryFn, + queryKeyHashFn, + getPreviousPageParam, + getNextPageParam, + initialPageParam, + } = defaultOptions as CreateBaseQueryOptions + const getPrimaryKey = () => primaryKey const getKey = (variables?: any) => getQueryKey(primaryKey, variables) diff --git a/src/utils.ts b/src/utils.ts index 9b7ce79..c10b36d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -39,6 +39,7 @@ export const suspenseOptions = { enabled: true, suspense: true, throwOnError: true, + // Compatible with ReactQuery v4 useErrorBoundary: true, }