diff --git a/README.md b/README.md index 5eb1a3a309..8da120a9e7 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,6 @@ This library is being built and maintained by me, @tannerlinsley and I am always - - [Installation](#installation) - [Defaults to keep in mind](#defaults-to-keep-in-mind) - [Quick Start](#quick-start) @@ -2323,10 +2322,10 @@ import { ReactQueryConfigProvider } from 'react-query' const queryConfig = { shared: { suspense: false, - queryKeySerializerFn: defaultQueryKeySerializerFn, }, queries: { - ...shared, + suspense, // defaults to `shared.suspense` + queryKeySerializerFn: defaultQueryKeySerializerFn, queryFn, enabled: true, retry: 3, @@ -2344,7 +2343,7 @@ const queryConfig = { useErrorBoundary: false, // falls back to suspense }, mutations: { - ...shared, + suspense, // defaults to `shared.suspense` throwOnError: false, onMutate: noop, onError: noop, diff --git a/src/config.js b/src/config.js index 2af2ef39d1..16a310282f 100644 --- a/src/config.js +++ b/src/config.js @@ -6,9 +6,9 @@ export const configContext = React.createContext() const DEFAULT_CONFIG = { shared: { suspense: false, - queryKeySerializerFn: defaultQueryKeySerializerFn, }, queries: { + queryKeySerializerFn: defaultQueryKeySerializerFn, queryFn: undefined, enabled: true, retry: 3, diff --git a/src/queryCache.js b/src/queryCache.js index e0a891073b..97dd568cbf 100644 --- a/src/queryCache.js +++ b/src/queryCache.js @@ -108,7 +108,7 @@ export function makeQueryCache({ frozen = isServer, defaultConfig } = {}) { const [ queryHash, queryKey, - ] = configRef.current.shared.queryKeySerializerFn(predicate) + ] = configRef.current.queries.queryKeySerializerFn(predicate) predicate = d => exact ? d.queryHash === queryHash : deepIncludes(d.queryKey, queryKey) diff --git a/types/index.d.ts b/types/index.d.ts index ec56607d9b..5152e049c2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -305,14 +305,6 @@ export type InfiniteQueryFunction< export interface BaseSharedOptions { suspense: boolean - queryKeySerializerFn?: ( - queryKey: - | QueryKeyPart[] - | string - | false - | undefined - | (() => QueryKeyPart[] | string | false | undefined) - ) => [string, QueryKeyPart[]] | [] } export interface BaseQueryOptions { @@ -357,7 +349,8 @@ export interface PrefetchQueryOptions throwOnError?: boolean } -export interface SetQueryDataQueryOptions extends QueryOptions { +export interface SetQueryDataQueryOptions + extends QueryOptions { exact?: boolean } @@ -475,7 +468,7 @@ export function useMutation( export type MutationFunction = ( variables: TVariables, - mutateOptions?: MutateOptions, + mutateOptions?: MutateOptions ) => Promise export interface MutateOptions { @@ -504,7 +497,10 @@ export type MutateFunction< TError = Error > = undefined extends TVariables ? (options?: MutateOptions) => Promise - : (variables: TVariables, options?: MutateOptions) => Promise + : ( + variables: TVariables, + options?: MutateOptions + ) => Promise export interface MutationResultBase { status: 'idle' | 'loading' | 'error' | 'success' @@ -637,7 +633,10 @@ export interface QueryCache { getQueryData(key: AnyQueryKey | string): T | undefined setQueryData( key: AnyQueryKey | string, - dataOrUpdater: TResult | undefined | ((oldData: TResult | undefined) => TResult | undefined), + dataOrUpdater: + | TResult + | undefined + | ((oldData: TResult | undefined) => TResult | undefined), config?: SetQueryDataQueryOptions ): void invalidateQueries( @@ -712,6 +711,14 @@ export interface ReactQueryProviderConfig { /** Defaults to the value of `suspense` if not defined otherwise */ useErrorBoundary?: boolean refetchOnWindowFocus?: boolean + queryKeySerializerFn?: ( + queryKey: + | QueryKeyPart[] + | string + | false + | undefined + | (() => QueryKeyPart[] | string | false | undefined) + ) => [string, QueryKeyPart[]] | [] } shared?: BaseSharedOptions mutations?: {