Interface UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>

interface UseQueryOptions {
    _defaulted?: boolean;
    _optimisticResults?: "optimistic" | "isRestoring";
    behavior?: QueryBehavior<TQueryFnData, TError, TQueryFnData, QueryKey>;
    cacheTime?: number;
    context?: Context<undefined | QueryClient>;
    enabled?: boolean;
    getNextPageParam?: GetNextPageParamFunction<TQueryFnData>;
    getPreviousPageParam?: GetPreviousPageParamFunction<TQueryFnData>;
    initialData?: TQueryFnData | InitialDataFunction<TQueryFnData>;
    initialDataUpdatedAt?: number | (() => undefined | number);
    isDataEqual?: ((oldData, newData) => boolean);
    keepPreviousData?: boolean;
    meta?: QueryMeta;
    networkMode?: NetworkMode;
    notifyOnChangeProps?: NotifyOnChangeProps;
    onError?: ((err) => void);
    onSettled?: ((data, error) => void);
    onSuccess?: ((data) => void);
    placeholderData?: TQueryFnData | PlaceholderDataFunction<TQueryFnData>;
    queryFn?: QueryFunction<TQueryFnData, TQueryKey, any>;
    queryHash?: string;
    queryKey?: TQueryKey;
    queryKeyHashFn?: QueryKeyHashFunction<TQueryKey>;
    refetchInterval?: number | false | ((data, query) => number | false);
    refetchIntervalInBackground?: boolean;
    refetchOnMount?: boolean | "always" | ((query) => boolean | "always");
    refetchOnReconnect?: boolean | "always" | ((query) => boolean | "always");
    refetchOnWindowFocus?: boolean | "always" | ((query) => boolean | "always");
    retry?: RetryValue<TError>;
    retryDelay?: RetryDelayValue<TError>;
    retryOnMount?: boolean;
    select?: ((data) => TData);
    staleTime?: number;
    structuralSharing?: boolean | ((oldData, newData) => TQueryFnData);
    suspense?: boolean;
    useErrorBoundary?: UseErrorBoundary<TQueryFnData, TError, TQueryFnData, TQueryKey>;
}

Type Parameters

  • TQueryFnData = unknown

  • TError = unknown

  • TData = TQueryFnData

  • TQueryKey extends QueryKey = QueryKey

Hierarchy

Properties

_defaulted?: boolean
_optimisticResults?: "optimistic" | "isRestoring"
behavior?: QueryBehavior<TQueryFnData, TError, TQueryFnData, QueryKey>
cacheTime?: number
context?: Context<undefined | QueryClient>

Use this to pass your React Query context. Otherwise, defaultContext will be used.

enabled?: boolean

Set this to false to disable automatic refetching when the query mounts or changes query keys. To refetch the query, use the refetch method returned from the useQuery instance. Defaults to true.

getNextPageParam?: GetNextPageParamFunction<TQueryFnData>

This function can be set to automatically get the next cursor for infinite queries. The result will also be used to determine the value of hasNextPage.

getPreviousPageParam?: GetPreviousPageParamFunction<TQueryFnData>

This function can be set to automatically get the previous cursor for infinite queries. The result will also be used to determine the value of hasPreviousPage.

initialData?: TQueryFnData | InitialDataFunction<TQueryFnData>
initialDataUpdatedAt?: number | (() => undefined | number)

Type declaration

    • (): undefined | number
    • Returns undefined | number

isDataEqual?: ((oldData, newData) => boolean)

Type declaration

    • (oldData, newData): boolean
    • Parameters

      • oldData: undefined | TQueryFnData
      • newData: TQueryFnData

      Returns boolean

      Deprecated

      This callback will be removed in the next major version. You can achieve the same functionality by passing a function to structuralSharing instead.

keepPreviousData?: boolean

Set this to true to keep the previous data when fetching based on a new query key. Defaults to false.

meta?: QueryMeta

Additional payload to be stored on each query. Use this property to pass information that can be used in other places.

networkMode?: NetworkMode
notifyOnChangeProps?: NotifyOnChangeProps

If set, the component will only re-render if any of the listed properties change. When set to ['data', 'error'], the component will only re-render when the data or error properties change. When set to 'all', the component will re-render whenever a query is updated. When set to a function, the function will be executed to compute the list of properties. By default, access to properties will be tracked, and the component will only re-render when one of the tracked properties change.

onError?: ((err) => void)

Type declaration

    • (err): void
    • This callback will fire if the query encounters an error and will be passed the error.

      Parameters

      • err: TError

      Returns void

      Deprecated

      This callback will be removed in the next major version.

onSettled?: ((data, error) => void)

Type declaration

    • (data, error): void
    • This callback will fire any time the query is either successfully fetched or errors and be passed either the data or error.

      Parameters

      • data: undefined | TData
      • error: null | TError

      Returns void

      Deprecated

      This callback will be removed in the next major version.

onSuccess?: ((data) => void)

Type declaration

    • (data): void
    • This callback will fire any time the query successfully fetches new data.

      Parameters

      • data: TData

      Returns void

      Deprecated

      This callback will be removed in the next major version.

placeholderData?: TQueryFnData | PlaceholderDataFunction<TQueryFnData>

If set, this value will be used as the placeholder data for this particular query observer while the query is still in the loading data and no initialData has been provided.

queryFn?: QueryFunction<TQueryFnData, TQueryKey, any>
queryHash?: string
queryKey?: TQueryKey
queryKeyHashFn?: QueryKeyHashFunction<TQueryKey>
refetchInterval?: number | false | ((data, query) => number | false)

If set to a number, the query will continuously refetch at this frequency in milliseconds. If set to a function, the function will be executed with the latest data and query to compute a frequency Defaults to false.

Type declaration

    • (data, query): number | false
    • Parameters

      • data: undefined | TData
      • query: Query<TQueryFnData, TError, TQueryFnData, TQueryKey>

      Returns number | false

refetchIntervalInBackground?: boolean

If set to true, the query will continue to refetch while their tab/window is in the background. Defaults to false.

refetchOnMount?: boolean | "always" | ((query) => boolean | "always")

If set to true, the query will refetch on mount if the data is stale. If set to false, will disable additional instances of a query to trigger background refetches. If set to 'always', the query will always refetch on mount. If set to a function, the function will be executed with the latest data and query to compute the value Defaults to true.

Type declaration

    • (query): boolean | "always"
    • Parameters

      • query: Query<TQueryFnData, TError, TQueryFnData, TQueryKey>

      Returns boolean | "always"

refetchOnReconnect?: boolean | "always" | ((query) => boolean | "always")

If set to true, the query will refetch on reconnect if the data is stale. If set to false, the query will not refetch on reconnect. If set to 'always', the query will always refetch on reconnect. If set to a function, the function will be executed with the latest data and query to compute the value. Defaults to the value of networkOnline (true)

Type declaration

    • (query): boolean | "always"
    • Parameters

      • query: Query<TQueryFnData, TError, TQueryFnData, TQueryKey>

      Returns boolean | "always"

refetchOnWindowFocus?: boolean | "always" | ((query) => boolean | "always")

If set to true, the query will refetch on window focus if the data is stale. If set to false, the query will not refetch on window focus. If set to 'always', the query will always refetch on window focus. If set to a function, the function will be executed with the latest data and query to compute the value. Defaults to true.

Type declaration

    • (query): boolean | "always"
    • Parameters

      • query: Query<TQueryFnData, TError, TQueryFnData, TQueryKey>

      Returns boolean | "always"

retry?: RetryValue<TError>

If false, failed queries will not retry by default. If true, failed queries will retry infinitely., failureCount: num If set to an integer number, e.g. 3, failed queries will retry until the failed query count meets that number. If set to a function (failureCount, error) => boolean failed queries will retry until the function returns false.

retryDelay?: RetryDelayValue<TError>
retryOnMount?: boolean

If set to false, the query will not be retried on mount if it contains an error. Defaults to true.

select?: ((data) => TData)

Type declaration

    • (data): TData
    • This option can be used to transform or select a part of the data returned by the query function.

      Parameters

      • data: TQueryFnData

      Returns TData

staleTime?: number

The time in milliseconds after data is considered stale. If set to Infinity, the data will never be considered stale.

structuralSharing?: boolean | ((oldData, newData) => TQueryFnData)

Set this to false to disable structural sharing between query results. Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic. Defaults to true.

Type declaration

    • (oldData, newData): TQueryFnData
    • Parameters

      • oldData: undefined | TQueryFnData
      • newData: TQueryFnData

      Returns TQueryFnData

suspense?: boolean

If set to true, the query will suspend when status === 'loading' and throw errors when status === 'error'. Defaults to false.

useErrorBoundary?: UseErrorBoundary<TQueryFnData, TError, TQueryFnData, TQueryKey>

Whether errors should be thrown instead of setting the error property. If set to true or suspense is true, all errors will be thrown to the error boundary. If set to false and suspense is false, errors are returned as state. If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (true) or return the error as state (false). Defaults to false.

Generated using TypeDoc