import { Removable } from './removable.js'; import { Subscribable } from './subscribable.js'; type QueryObserverListener = (result: QueryObserverResult) => void; interface NotifyOptions { listeners?: boolean; } interface ObserverFetchOptions extends FetchOptions { throwOnError?: boolean; } declare class QueryObserver extends Subscribable> { #private; options: QueryObserverOptions; constructor(client: QueryClient, options: QueryObserverOptions); protected bindMethods(): void; protected onSubscribe(): void; protected onUnsubscribe(): void; shouldFetchOnReconnect(): boolean; shouldFetchOnWindowFocus(): boolean; destroy(): void; setOptions(options: QueryObserverOptions, notifyOptions?: NotifyOptions): void; getOptimisticResult(options: DefaultedQueryObserverOptions): QueryObserverResult; getCurrentResult(): QueryObserverResult; trackResult(result: QueryObserverResult, onPropTracked?: (key: keyof QueryObserverResult) => void): QueryObserverResult; trackProp(key: keyof QueryObserverResult): void; getCurrentQuery(): Query; refetch({ ...options }?: RefetchOptions): Promise>; fetchOptimistic(options: QueryObserverOptions): Promise>; protected fetch(fetchOptions: ObserverFetchOptions): Promise>; protected createResult(query: Query, options: QueryObserverOptions): QueryObserverResult; updateResult(notifyOptions?: NotifyOptions): void; onQueryUpdate(): void; } interface QueryConfig { cache: QueryCache; queryKey: TQueryKey; queryHash: string; options?: QueryOptions; defaultOptions?: QueryOptions; state?: QueryState; } interface QueryState { data: TData | undefined; dataUpdateCount: number; dataUpdatedAt: number; error: TError | null; errorUpdateCount: number; errorUpdatedAt: number; fetchFailureCount: number; fetchFailureReason: TError | null; fetchMeta: FetchMeta | null; isInvalidated: boolean; status: QueryStatus; fetchStatus: FetchStatus; } interface FetchContext { fetchFn: () => unknown | Promise; fetchOptions?: FetchOptions; signal: AbortSignal; options: QueryOptions; queryKey: TQueryKey; state: QueryState; } interface QueryBehavior { onFetch: (context: FetchContext, query: Query) => void; } type FetchDirection = 'forward' | 'backward'; interface FetchMeta { fetchMore?: { direction: FetchDirection; }; } interface FetchOptions { cancelRefetch?: boolean; meta?: FetchMeta; initialPromise?: Promise; } interface FailedAction$1 { type: 'failed'; failureCount: number; error: TError; } interface FetchAction { type: 'fetch'; meta?: FetchMeta; } interface SuccessAction$1 { data: TData | undefined; type: 'success'; dataUpdatedAt?: number; manual?: boolean; } interface ErrorAction$1 { type: 'error'; error: TError; } interface InvalidateAction { type: 'invalidate'; } interface PauseAction$1 { type: 'pause'; } interface ContinueAction$1 { type: 'continue'; } interface SetStateAction { type: 'setState'; state: Partial>; setStateOptions?: SetStateOptions; } type Action$1 = ContinueAction$1 | ErrorAction$1 | FailedAction$1 | FetchAction | InvalidateAction | PauseAction$1 | SetStateAction | SuccessAction$1; interface SetStateOptions { meta?: any; } declare class Query extends Removable { #private; queryKey: TQueryKey; queryHash: string; options: QueryOptions; state: QueryState; observers: Array>; constructor(config: QueryConfig); get meta(): QueryMeta | undefined; get promise(): Promise | undefined; setOptions(options?: QueryOptions): void; protected optionalRemove(): void; setData(newData: TData, options?: SetDataOptions & { manual: boolean; }): TData; setState(state: Partial>, setStateOptions?: SetStateOptions): void; cancel(options?: CancelOptions): Promise; destroy(): void; reset(): void; isActive(): boolean; isDisabled(): boolean; isStale(): boolean; isStaleByTime(staleTime?: number): boolean; onFocus(): void; onOnline(): void; addObserver(observer: QueryObserver): void; removeObserver(observer: QueryObserver): void; getObserversCount(): number; invalidate(): void; fetch(options?: QueryOptions, fetchOptions?: FetchOptions): Promise; } declare function fetchState(data: TData | undefined, options: QueryOptions): { readonly error?: null | undefined; readonly status?: "pending" | undefined; readonly fetchFailureCount: 0; readonly fetchFailureReason: null; readonly fetchStatus: "fetching" | "paused"; }; interface QueryFilters { /** * Filter to active queries, inactive queries or all queries */ type?: QueryTypeFilter; /** * Match query key exactly */ exact?: boolean; /** * Include queries matching this predicate function */ predicate?: (query: Query) => boolean; /** * Include queries matching this query key */ queryKey?: QueryKey; /** * Include or exclude stale queries */ stale?: boolean; /** * Include queries matching their fetchStatus */ fetchStatus?: FetchStatus; } interface MutationFilters { /** * Match mutation key exactly */ exact?: boolean; /** * Include mutations matching this predicate function */ predicate?: (mutation: Mutation) => boolean; /** * Include mutations matching this mutation key */ mutationKey?: MutationKey; /** * Filter by mutation status */ status?: MutationStatus; } type Updater = TOutput | ((input: TInput) => TOutput); type QueryTypeFilter = 'all' | 'active' | 'inactive'; declare const isServer: boolean; declare function noop(): undefined; declare function functionalUpdate(updater: Updater, input: TInput): TOutput; declare function isValidTimeout(value: unknown): value is number; declare function timeUntilStale(updatedAt: number, staleTime?: number): number; declare function resolveStaleTime(staleTime: undefined | StaleTime, query: Query): number | undefined; declare function resolveEnabled(enabled: undefined | Enabled, query: Query): boolean | undefined; declare function matchQuery(filters: QueryFilters, query: Query): boolean; declare function matchMutation(filters: MutationFilters, mutation: Mutation): boolean; declare function hashQueryKeyByOptions(queryKey: TQueryKey, options?: Pick, 'queryKeyHashFn'>): string; /** * Default query & mutation keys hash function. * Hashes the value into a stable hash. */ declare function hashKey(queryKey: QueryKey | MutationKey): string; /** * Checks if key `b` partially matches with key `a`. */ declare function partialMatchKey(a: QueryKey, b: QueryKey): boolean; /** * This function returns `a` if `b` is deeply equal. * If not, it will replace any deeply equal children of `b` with those of `a`. * This can be used for structural sharing between JSON values for example. */ declare function replaceEqualDeep(a: unknown, b: T): T; /** * Shallow compare objects. */ declare function shallowEqualObjects>(a: T, b: T | undefined): boolean; declare function isPlainArray(value: unknown): boolean; declare function isPlainObject(o: any): o is Object; declare function sleep(timeout: number): Promise; declare function replaceData>(prevData: TData | undefined, data: TData, options: TOptions): TData; declare function keepPreviousData(previousData: T | undefined): T | undefined; declare function addToEnd(items: Array, item: T, max?: number): Array; declare function addToStart(items: Array, item: T, max?: number): Array; declare const skipToken: unique symbol; type SkipToken = typeof skipToken; declare function ensureQueryFn(options: { queryFn?: QueryFunction | SkipToken; queryHash?: string; }, fetchOptions?: FetchOptions): QueryFunction; interface QueryCacheConfig { onError?: (error: DefaultError, query: Query) => void; onSuccess?: (data: unknown, query: Query) => void; onSettled?: (data: unknown | undefined, error: DefaultError | null, query: Query) => void; } interface NotifyEventQueryAdded extends NotifyEvent { type: 'added'; query: Query; } interface NotifyEventQueryRemoved extends NotifyEvent { type: 'removed'; query: Query; } interface NotifyEventQueryUpdated extends NotifyEvent { type: 'updated'; query: Query; action: Action$1; } interface NotifyEventQueryObserverAdded extends NotifyEvent { type: 'observerAdded'; query: Query; observer: QueryObserver; } interface NotifyEventQueryObserverRemoved extends NotifyEvent { type: 'observerRemoved'; query: Query; observer: QueryObserver; } interface NotifyEventQueryObserverResultsUpdated extends NotifyEvent { type: 'observerResultsUpdated'; query: Query; } interface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent { type: 'observerOptionsUpdated'; query: Query; observer: QueryObserver; } type QueryCacheNotifyEvent = NotifyEventQueryAdded | NotifyEventQueryRemoved | NotifyEventQueryUpdated | NotifyEventQueryObserverAdded | NotifyEventQueryObserverRemoved | NotifyEventQueryObserverResultsUpdated | NotifyEventQueryObserverOptionsUpdated; type QueryCacheListener = (event: QueryCacheNotifyEvent) => void; interface QueryStore { has: (queryHash: string) => boolean; set: (queryHash: string, query: Query) => void; get: (queryHash: string) => Query | undefined; delete: (queryHash: string) => void; values: () => IterableIterator; } declare class QueryCache extends Subscribable { #private; config: QueryCacheConfig; constructor(config?: QueryCacheConfig); build(client: QueryClient, options: WithRequired, 'queryKey'>, state?: QueryState): Query; add(query: Query): void; remove(query: Query): void; clear(): void; get(queryHash: string): Query | undefined; getAll(): Array; find(filters: WithRequired): Query | undefined; findAll(filters?: QueryFilters): Array; notify(event: QueryCacheNotifyEvent): void; onFocus(): void; onOnline(): void; } declare class QueryClient { #private; constructor(config?: QueryClientConfig); mount(): void; unmount(): void; isFetching(filters?: QueryFilters): number; isMutating(filters?: MutationFilters): number; getQueryData ? TaggedValue : TQueryFnData>(queryKey: TTaggedQueryKey): TInferredQueryFnData | undefined; ensureQueryData(options: EnsureQueryDataOptions): Promise; getQueriesData(filters: QueryFilters): Array<[QueryKey, TQueryFnData | undefined]>; setQueryData ? TaggedValue : TQueryFnData>(queryKey: TTaggedQueryKey, updater: Updater | undefined, NoInfer | undefined>, options?: SetDataOptions): TInferredQueryFnData | undefined; setQueriesData(filters: QueryFilters, updater: Updater, options?: SetDataOptions): Array<[QueryKey, TQueryFnData | undefined]>; getQueryState ? TaggedValue : TQueryFnData>(queryKey: TTaggedQueryKey): QueryState | undefined; removeQueries(filters?: QueryFilters): void; resetQueries(filters?: QueryFilters, options?: ResetOptions): Promise; cancelQueries(filters?: QueryFilters, cancelOptions?: CancelOptions): Promise; invalidateQueries(filters?: InvalidateQueryFilters, options?: InvalidateOptions): Promise; refetchQueries(filters?: RefetchQueryFilters, options?: RefetchOptions): Promise; fetchQuery(options: FetchQueryOptions): Promise; prefetchQuery(options: FetchQueryOptions): Promise; fetchInfiniteQuery(options: FetchInfiniteQueryOptions): Promise>; prefetchInfiniteQuery(options: FetchInfiniteQueryOptions): Promise; ensureInfiniteQueryData(options: EnsureInfiniteQueryDataOptions): Promise>; resumePausedMutations(): Promise; getQueryCache(): QueryCache; getMutationCache(): MutationCache; getDefaultOptions(): DefaultOptions; setDefaultOptions(options: DefaultOptions): void; setQueryDefaults(queryKey: QueryKey, options: Partial, 'queryKey'>>): void; getQueryDefaults(queryKey: QueryKey): OmitKeyof, 'queryKey'>; setMutationDefaults(mutationKey: MutationKey, options: OmitKeyof, 'mutationKey'>): void; getMutationDefaults(mutationKey: MutationKey): MutationObserverOptions; defaultQueryOptions(options: QueryObserverOptions | DefaultedQueryObserverOptions): DefaultedQueryObserverOptions; defaultMutationOptions>(options?: T): T; clear(): void; } type MutationObserverListener = (result: MutationObserverResult) => void; declare class MutationObserver extends Subscribable> { #private; options: MutationObserverOptions; constructor(client: QueryClient, options: MutationObserverOptions); protected bindMethods(): void; setOptions(options: MutationObserverOptions): void; protected onUnsubscribe(): void; onMutationUpdate(action: Action): void; getCurrentResult(): MutationObserverResult; reset(): void; mutate(variables: TVariables, options?: MutateOptions): Promise; } interface MutationCacheConfig { onError?: (error: DefaultError, variables: unknown, context: unknown, mutation: Mutation) => Promise | unknown; onSuccess?: (data: unknown, variables: unknown, context: unknown, mutation: Mutation) => Promise | unknown; onMutate?: (variables: unknown, mutation: Mutation) => Promise | unknown; onSettled?: (data: unknown | undefined, error: DefaultError | null, variables: unknown, context: unknown, mutation: Mutation) => Promise | unknown; } interface NotifyEventMutationAdded extends NotifyEvent { type: 'added'; mutation: Mutation; } interface NotifyEventMutationRemoved extends NotifyEvent { type: 'removed'; mutation: Mutation; } interface NotifyEventMutationObserverAdded extends NotifyEvent { type: 'observerAdded'; mutation: Mutation; observer: MutationObserver; } interface NotifyEventMutationObserverRemoved extends NotifyEvent { type: 'observerRemoved'; mutation: Mutation; observer: MutationObserver; } interface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent { type: 'observerOptionsUpdated'; mutation?: Mutation; observer: MutationObserver; } interface NotifyEventMutationUpdated extends NotifyEvent { type: 'updated'; mutation: Mutation; action: Action; } type MutationCacheNotifyEvent = NotifyEventMutationAdded | NotifyEventMutationRemoved | NotifyEventMutationObserverAdded | NotifyEventMutationObserverRemoved | NotifyEventMutationObserverOptionsUpdated | NotifyEventMutationUpdated; type MutationCacheListener = (event: MutationCacheNotifyEvent) => void; declare class MutationCache extends Subscribable { #private; config: MutationCacheConfig; constructor(config?: MutationCacheConfig); build(client: QueryClient, options: MutationOptions, state?: MutationState): Mutation; add(mutation: Mutation): void; remove(mutation: Mutation): void; canRun(mutation: Mutation): boolean; runNext(mutation: Mutation): Promise; clear(): void; getAll(): Array; find(filters: MutationFilters): Mutation | undefined; findAll(filters?: MutationFilters): Array; notify(event: MutationCacheNotifyEvent): void; resumePausedMutations(): Promise; } interface MutationConfig { mutationId: number; mutationCache: MutationCache; options: MutationOptions; state?: MutationState; } interface MutationState { context: TContext | undefined; data: TData | undefined; error: TError | null; failureCount: number; failureReason: TError | null; isPaused: boolean; status: MutationStatus; variables: TVariables | undefined; submittedAt: number; } interface FailedAction { type: 'failed'; failureCount: number; error: TError | null; } interface PendingAction { type: 'pending'; isPaused: boolean; variables?: TVariables; context?: TContext; } interface SuccessAction { type: 'success'; data: TData; } interface ErrorAction { type: 'error'; error: TError; } interface PauseAction { type: 'pause'; } interface ContinueAction { type: 'continue'; } type Action = ContinueAction | ErrorAction | FailedAction | PendingAction | PauseAction | SuccessAction; declare class Mutation extends Removable { #private; state: MutationState; options: MutationOptions; readonly mutationId: number; constructor(config: MutationConfig); setOptions(options: MutationOptions): void; get meta(): MutationMeta | undefined; addObserver(observer: MutationObserver): void; removeObserver(observer: MutationObserver): void; protected optionalRemove(): void; continue(): Promise; execute(variables: TVariables): Promise; } declare function getDefaultState(): MutationState; interface RetryerConfig { fn: () => TData | Promise; initialPromise?: Promise; abort?: () => void; onError?: (error: TError) => void; onSuccess?: (data: TData) => void; onFail?: (failureCount: number, error: TError) => void; onPause?: () => void; onContinue?: () => void; retry?: RetryValue; retryDelay?: RetryDelayValue; networkMode: NetworkMode | undefined; canRun: () => boolean; } interface Retryer { promise: Promise; cancel: (cancelOptions?: CancelOptions) => void; continue: () => Promise; cancelRetry: () => void; continueRetry: () => void; canStart: () => boolean; start: () => Promise; } type RetryValue = boolean | number | ShouldRetryFunction; type ShouldRetryFunction = (failureCount: number, error: TError) => boolean; type RetryDelayValue = number | RetryDelayFunction; type RetryDelayFunction = (failureCount: number, error: TError) => number; declare function canFetch(networkMode: NetworkMode | undefined): boolean; declare class CancelledError extends Error { revert?: boolean; silent?: boolean; constructor(options?: CancelOptions); } declare function isCancelledError(value: any): value is CancelledError; declare function createRetryer(config: RetryerConfig): Retryer; type OmitKeyof) | (number & Record) | (symbol & Record) : keyof TObject, TStrictly extends 'strictly' | 'safely' = 'strictly'> = Omit; type Override = { [AKey in keyof TTargetA]: AKey extends keyof TTargetB ? TTargetB[AKey] : TTargetA[AKey]; }; type NoInfer = [T][T extends any ? 0 : never]; interface Register { } type DefaultError = Register extends { defaultError: infer TError; } ? TError : Error; type QueryKey = ReadonlyArray; declare const dataTagSymbol: unique symbol; type DataTag = TType & { [dataTagSymbol]: TValue; }; type QueryFunction = (context: QueryFunctionContext) => T | Promise; type StaleTime = number | ((query: Query) => number); type Enabled = boolean | ((query: Query) => boolean); type QueryPersister = [TPageParam] extends [never] ? (queryFn: QueryFunction, context: QueryFunctionContext, query: Query) => T | Promise : (queryFn: QueryFunction, context: QueryFunctionContext, query: Query) => T | Promise; type QueryFunctionContext = [TPageParam] extends [never] ? { queryKey: TQueryKey; signal: AbortSignal; meta: QueryMeta | undefined; pageParam?: unknown; /** * @deprecated * if you want access to the direction, you can add it to the pageParam */ direction?: unknown; } : { queryKey: TQueryKey; signal: AbortSignal; pageParam: TPageParam; /** * @deprecated * if you want access to the direction, you can add it to the pageParam */ direction: FetchDirection; meta: QueryMeta | undefined; }; type InitialDataFunction = () => T | undefined; type NonFunctionGuard = T extends Function ? never : T; type PlaceholderDataFunction = (previousData: TQueryData | undefined, previousQuery: Query | undefined) => TQueryData | undefined; type QueriesPlaceholderDataFunction = (previousData: undefined, previousQuery: undefined) => TQueryData | undefined; type QueryKeyHashFunction = (queryKey: TQueryKey) => string; type GetPreviousPageParamFunction = (firstPage: TQueryFnData, allPages: Array, firstPageParam: TPageParam, allPageParams: Array) => TPageParam | undefined | null; type GetNextPageParamFunction = (lastPage: TQueryFnData, allPages: Array, lastPageParam: TPageParam, allPageParams: Array) => TPageParam | undefined | null; interface InfiniteData { pages: Array; pageParams: Array; } type QueryMeta = Register extends { queryMeta: infer TQueryMeta; } ? TQueryMeta extends Record ? TQueryMeta : Record : Record; type NetworkMode = 'online' | 'always' | 'offlineFirst'; type NotifyOnChangeProps = Array | 'all' | undefined | (() => Array | 'all' | undefined); interface QueryOptions { /** * 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. */ retry?: RetryValue; retryDelay?: RetryDelayValue; networkMode?: NetworkMode; /** * The time in milliseconds that unused/inactive cache data remains in memory. * When a query's cache becomes unused or inactive, that cache data will be garbage collected after this duration. * When different garbage collection times are specified, the longest one will be used. * Setting it to `Infinity` will disable garbage collection. */ gcTime?: number; queryFn?: QueryFunction | SkipToken; persister?: QueryPersister, NoInfer, NoInfer>; queryHash?: string; queryKey?: TQueryKey; queryKeyHashFn?: QueryKeyHashFunction; initialData?: TData | InitialDataFunction; initialDataUpdatedAt?: number | (() => number | undefined); behavior?: QueryBehavior; /** * 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`. */ structuralSharing?: boolean | ((oldData: unknown | undefined, newData: unknown) => unknown); _defaulted?: boolean; /** * Additional payload to be stored on each query. * Use this property to pass information that can be used in other places. */ meta?: QueryMeta; /** * Maximum number of pages to store in the data of an infinite query. */ maxPages?: number; } interface InitialPageParam { initialPageParam: TPageParam; } interface InfiniteQueryPageParamsOptions extends InitialPageParam { /** * 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`. */ getPreviousPageParam?: GetPreviousPageParamFunction; /** * 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`. */ getNextPageParam: GetNextPageParamFunction; } type ThrowOnError = boolean | ((error: TError, query: Query) => boolean); interface QueryObserverOptions extends WithRequired, 'queryKey'> { /** * Set this to `false` or a function that returns `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. * Accepts a boolean or function that returns a boolean. * Defaults to `true`. */ enabled?: Enabled; /** * The time in milliseconds after data is considered stale. * If set to `Infinity`, the data will never be considered stale. * If set to a function, the function will be executed with the query to compute a `staleTime`. */ staleTime?: StaleTime; /** * 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`. */ refetchInterval?: number | false | ((query: Query) => number | false | undefined); /** * If set to `true`, the query will continue to refetch while their tab/window is in the background. * Defaults to `false`. */ refetchIntervalInBackground?: boolean; /** * 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`. */ refetchOnWindowFocus?: boolean | 'always' | ((query: 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`) */ refetchOnReconnect?: boolean | 'always' | ((query: 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 refetch. * 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`. */ refetchOnMount?: boolean | 'always' | ((query: Query) => boolean | 'always'); /** * If set to `false`, the query will not be retried on mount if it contains an error. * Defaults to `true`. */ retryOnMount?: boolean; /** * 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. */ notifyOnChangeProps?: NotifyOnChangeProps; /** * 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`. */ throwOnError?: ThrowOnError; /** * This option can be used to transform or select a part of the data returned by the query function. */ select?: (data: TQueryData) => TData; /** * If set to `true`, the query will suspend when `status === 'pending'` * and throw errors when `status === 'error'`. * Defaults to `false`. */ suspense?: boolean; /** * 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. */ placeholderData?: NonFunctionGuard | PlaceholderDataFunction, TError, NonFunctionGuard, TQueryKey>; _optimisticResults?: 'optimistic' | 'isRestoring'; /** * Enable prefetching during rendering */ experimental_prefetchInRender?: boolean; } type WithRequired = TTarget & { [_ in TKey]: {}; }; type Optional = Pick, TKey> & OmitKeyof; type DefaultedQueryObserverOptions = WithRequired, 'throwOnError' | 'refetchOnReconnect' | 'queryHash'>; interface InfiniteQueryObserverOptions extends QueryObserverOptions, TQueryKey, TPageParam>, InfiniteQueryPageParamsOptions { } type DefaultedInfiniteQueryObserverOptions = WithRequired, 'throwOnError' | 'refetchOnReconnect' | 'queryHash'>; interface FetchQueryOptions extends WithRequired, 'queryKey'> { initialPageParam?: never; /** * The time in milliseconds after data is considered stale. * If the data is fresh it will be returned from the cache. */ staleTime?: StaleTime; } interface EnsureQueryDataOptions extends FetchQueryOptions { revalidateIfStale?: boolean; } type EnsureInfiniteQueryDataOptions = FetchInfiniteQueryOptions & { revalidateIfStale?: boolean; }; type FetchInfiniteQueryPages = { pages?: never; } | { pages: number; getNextPageParam: GetNextPageParamFunction; }; type FetchInfiniteQueryOptions = Omit, TQueryKey, TPageParam>, 'initialPageParam'> & InitialPageParam & FetchInfiniteQueryPages; interface ResultOptions { throwOnError?: boolean; } interface RefetchOptions extends ResultOptions { /** * If set to `true`, a currently running request will be cancelled before a new request is made * * If set to `false`, no refetch will be made if there is already a request running. * * Defaults to `true`. */ cancelRefetch?: boolean; } interface InvalidateQueryFilters extends QueryFilters { refetchType?: QueryTypeFilter | 'none'; } interface RefetchQueryFilters extends QueryFilters { } interface InvalidateOptions extends RefetchOptions { } interface ResetOptions extends RefetchOptions { } interface FetchNextPageOptions extends ResultOptions { /** * If set to `true`, calling `fetchNextPage` repeatedly will invoke `queryFn` every time, * whether the previous invocation has resolved or not. Also, the result from previous invocations will be ignored. * * If set to `false`, calling `fetchNextPage` repeatedly won't have any effect until the first invocation has resolved. * * Defaults to `true`. */ cancelRefetch?: boolean; } interface FetchPreviousPageOptions extends ResultOptions { /** * If set to `true`, calling `fetchPreviousPage` repeatedly will invoke `queryFn` every time, * whether the previous invocation has resolved or not. Also, the result from previous invocations will be ignored. * * If set to `false`, calling `fetchPreviousPage` repeatedly won't have any effect until the first invocation has resolved. * * Defaults to `true`. */ cancelRefetch?: boolean; } type QueryStatus = 'pending' | 'error' | 'success'; type FetchStatus = 'fetching' | 'paused' | 'idle'; interface QueryObserverBaseResult { /** * The last successfully resolved data for the query. */ data: TData | undefined; /** * The timestamp for when the query most recently returned the `status` as `"success"`. */ dataUpdatedAt: number; /** * The error object for the query, if an error was thrown. * - Defaults to `null`. */ error: TError | null; /** * The timestamp for when the query most recently returned the `status` as `"error"`. */ errorUpdatedAt: number; /** * The failure count for the query. * - Incremented every time the query fails. * - Reset to `0` when the query succeeds. */ failureCount: number; /** * The failure reason for the query retry. * - Reset to `null` when the query succeeds. */ failureReason: TError | null; /** * The sum of all errors. */ errorUpdateCount: number; /** * A derived boolean from the `status` variable, provided for convenience. * - `true` if the query attempt resulted in an error. */ isError: boolean; /** * Will be `true` if the query has been fetched. */ isFetched: boolean; /** * Will be `true` if the query has been fetched after the component mounted. * - This property can be used to not show any previously cached data. */ isFetchedAfterMount: boolean; /** * A derived boolean from the `fetchStatus` variable, provided for convenience. * - `true` whenever the `queryFn` is executing, which includes initial `pending` as well as background refetch. */ isFetching: boolean; /** * Is `true` whenever the first fetch for a query is in-flight. * - Is the same as `isFetching && isPending`. */ isLoading: boolean; /** * Will be `pending` if there's no cached data and no query attempt was finished yet. */ isPending: boolean; /** * Will be `true` if the query failed while fetching for the first time. */ isLoadingError: boolean; /** * @deprecated `isInitialLoading` is being deprecated in favor of `isLoading` * and will be removed in the next major version. */ isInitialLoading: boolean; /** * A derived boolean from the `fetchStatus` variable, provided for convenience. * - The query wanted to fetch, but has been `paused`. */ isPaused: boolean; /** * Will be `true` if the data shown is the placeholder data. */ isPlaceholderData: boolean; /** * Will be `true` if the query failed while refetching. */ isRefetchError: boolean; /** * Is `true` whenever a background refetch is in-flight, which _does not_ include initial `pending`. * - Is the same as `isFetching && !isPending`. */ isRefetching: boolean; /** * Will be `true` if the data in the cache is invalidated or if the data is older than the given `staleTime`. */ isStale: boolean; /** * A derived boolean from the `status` variable, provided for convenience. * - `true` if the query has received a response with no errors and is ready to display its data. */ isSuccess: boolean; /** * A function to manually refetch the query. */ refetch: (options?: RefetchOptions) => Promise>; /** * The status of the query. * - Will be: * - `pending` if there's no cached data and no query attempt was finished yet. * - `error` if the query attempt resulted in an error. * - `success` if the query has received a response with no errors and is ready to display its data. */ status: QueryStatus; /** * The fetch status of the query. * - `fetching`: Is `true` whenever the queryFn is executing, which includes initial `pending` as well as background refetch. * - `paused`: The query wanted to fetch, but has been `paused`. * - `idle`: The query is not fetching. * - See [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information. */ fetchStatus: FetchStatus; /** * A stable promise that will be resolved with the data of the query. * Requires the `experimental_prefetchInRender` feature flag to be enabled. * @example * * ### Enabling the feature flag * ```ts * const client = new QueryClient({ * defaultOptions: { * queries: { * experimental_prefetchInRender: true, * }, * }, * }) * ``` * * ### Usage * ```tsx * import { useQuery } from '@tanstack/react-query' * import React from 'react' * import { fetchTodos, type Todo } from './api' * * function TodoList({ query }: { query: UseQueryResult }) { * const data = React.use(query.promise) * * return ( *
    * {data.map(todo => ( *
  • {todo.title}
  • * ))} *
* ) * } * * export function App() { * const query = useQuery({ queryKey: ['todos'], queryFn: fetchTodos }) * * return ( * <> *

Todos

* Loading...}> * * * * ) * } * ``` */ promise: Promise; } interface QueryObserverPendingResult extends QueryObserverBaseResult { data: undefined; error: null; isError: false; isPending: true; isLoadingError: false; isRefetchError: false; isSuccess: false; status: 'pending'; } interface QueryObserverLoadingResult extends QueryObserverBaseResult { data: undefined; error: null; isError: false; isPending: true; isLoading: true; isLoadingError: false; isRefetchError: false; isSuccess: false; status: 'pending'; } interface QueryObserverLoadingErrorResult extends QueryObserverBaseResult { data: undefined; error: TError; isError: true; isPending: false; isLoading: false; isLoadingError: true; isRefetchError: false; isSuccess: false; status: 'error'; } interface QueryObserverRefetchErrorResult extends QueryObserverBaseResult { data: TData; error: TError; isError: true; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: true; isSuccess: false; status: 'error'; } interface QueryObserverSuccessResult extends QueryObserverBaseResult { data: TData; error: null; isError: false; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: false; isSuccess: true; status: 'success'; } type DefinedQueryObserverResult = QueryObserverRefetchErrorResult | QueryObserverSuccessResult; type QueryObserverResult = DefinedQueryObserverResult | QueryObserverLoadingErrorResult | QueryObserverLoadingResult | QueryObserverPendingResult; interface InfiniteQueryObserverBaseResult extends QueryObserverBaseResult { /** * This function allows you to fetch the next "page" of results. */ fetchNextPage: (options?: FetchNextPageOptions) => Promise>; /** * This function allows you to fetch the previous "page" of results. */ fetchPreviousPage: (options?: FetchPreviousPageOptions) => Promise>; /** * Will be `true` if there is a next page to be fetched (known via the `getNextPageParam` option). */ hasNextPage: boolean; /** * Will be `true` if there is a previous page to be fetched (known via the `getPreviousPageParam` option). */ hasPreviousPage: boolean; /** * Will be `true` if the query failed while fetching the next page. */ isFetchNextPageError: boolean; /** * Will be `true` while fetching the next page with `fetchNextPage`. */ isFetchingNextPage: boolean; /** * Will be `true` if the query failed while fetching the previous page. */ isFetchPreviousPageError: boolean; /** * Will be `true` while fetching the previous page with `fetchPreviousPage`. */ isFetchingPreviousPage: boolean; } interface InfiniteQueryObserverPendingResult extends InfiniteQueryObserverBaseResult { data: undefined; error: null; isError: false; isPending: true; isLoadingError: false; isRefetchError: false; isFetchNextPageError: false; isFetchPreviousPageError: false; isSuccess: false; status: 'pending'; } interface InfiniteQueryObserverLoadingResult extends InfiniteQueryObserverBaseResult { data: undefined; error: null; isError: false; isPending: true; isLoading: true; isLoadingError: false; isRefetchError: false; isFetchNextPageError: false; isFetchPreviousPageError: false; isSuccess: false; status: 'pending'; } interface InfiniteQueryObserverLoadingErrorResult extends InfiniteQueryObserverBaseResult { data: undefined; error: TError; isError: true; isPending: false; isLoading: false; isLoadingError: true; isRefetchError: false; isFetchNextPageError: false; isFetchPreviousPageError: false; isSuccess: false; status: 'error'; } interface InfiniteQueryObserverRefetchErrorResult extends InfiniteQueryObserverBaseResult { data: TData; error: TError; isError: true; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: true; isSuccess: false; status: 'error'; } interface InfiniteQueryObserverSuccessResult extends InfiniteQueryObserverBaseResult { data: TData; error: null; isError: false; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: false; isFetchNextPageError: false; isFetchPreviousPageError: false; isSuccess: true; status: 'success'; } type DefinedInfiniteQueryObserverResult = InfiniteQueryObserverRefetchErrorResult | InfiniteQueryObserverSuccessResult; type InfiniteQueryObserverResult = DefinedInfiniteQueryObserverResult | InfiniteQueryObserverLoadingErrorResult | InfiniteQueryObserverLoadingResult | InfiniteQueryObserverPendingResult; type MutationKey = ReadonlyArray; type MutationStatus = 'idle' | 'pending' | 'success' | 'error'; type MutationScope = { id: string; }; type MutationMeta = Register extends { mutationMeta: infer TMutationMeta; } ? TMutationMeta extends Record ? TMutationMeta : Record : Record; type MutationFunction = (variables: TVariables) => Promise; interface MutationOptions { mutationFn?: MutationFunction; mutationKey?: MutationKey; onMutate?: (variables: TVariables) => Promise | TContext | undefined; onSuccess?: (data: TData, variables: TVariables, context: TContext) => Promise | unknown; onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise | unknown; onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise | unknown; retry?: RetryValue; retryDelay?: RetryDelayValue; networkMode?: NetworkMode; gcTime?: number; _defaulted?: boolean; meta?: MutationMeta; scope?: MutationScope; } interface MutationObserverOptions extends MutationOptions { throwOnError?: boolean | ((error: TError) => boolean); } interface MutateOptions { onSuccess?: (data: TData, variables: TVariables, context: TContext) => void; onError?: (error: TError, variables: TVariables, context: TContext | undefined) => void; onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => void; } type MutateFunction = (variables: TVariables, options?: MutateOptions) => Promise; interface MutationObserverBaseResult extends MutationState { /** * The last successfully resolved data for the mutation. */ data: TData | undefined; /** * The variables object passed to the `mutationFn`. */ variables: TVariables | undefined; /** * The error object for the mutation, if an error was encountered. * - Defaults to `null`. */ error: TError | null; /** * A boolean variable derived from `status`. * - `true` if the last mutation attempt resulted in an error. */ isError: boolean; /** * A boolean variable derived from `status`. * - `true` if the mutation is in its initial state prior to executing. */ isIdle: boolean; /** * A boolean variable derived from `status`. * - `true` if the mutation is currently executing. */ isPending: boolean; /** * A boolean variable derived from `status`. * - `true` if the last mutation attempt was successful. */ isSuccess: boolean; /** * The status of the mutation. * - Will be: * - `idle` initial status prior to the mutation function executing. * - `pending` if the mutation is currently executing. * - `error` if the last mutation attempt resulted in an error. * - `success` if the last mutation attempt was successful. */ status: MutationStatus; /** * The mutation function you can call with variables to trigger the mutation and optionally hooks on additional callback options. * @param variables - The variables object to pass to the `mutationFn`. * @param options.onSuccess - This function will fire when the mutation is successful and will be passed the mutation's result. * @param options.onError - This function will fire if the mutation encounters an error and will be passed the error. * @param options.onSettled - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error. * @remarks * - If you make multiple requests, `onSuccess` will fire only after the latest call you've made. * - All the callback functions (`onSuccess`, `onError`, `onSettled`) are void functions, and the returned value will be ignored. */ mutate: MutateFunction; /** * A function to clean the mutation internal state (i.e., it resets the mutation to its initial state). */ reset: () => void; } interface MutationObserverIdleResult extends MutationObserverBaseResult { data: undefined; variables: undefined; error: null; isError: false; isIdle: true; isPending: false; isSuccess: false; status: 'idle'; } interface MutationObserverLoadingResult extends MutationObserverBaseResult { data: undefined; variables: TVariables; error: null; isError: false; isIdle: false; isPending: true; isSuccess: false; status: 'pending'; } interface MutationObserverErrorResult extends MutationObserverBaseResult { data: undefined; error: TError; variables: TVariables; isError: true; isIdle: false; isPending: false; isSuccess: false; status: 'error'; } interface MutationObserverSuccessResult extends MutationObserverBaseResult { data: TData; error: null; variables: TVariables; isError: false; isIdle: false; isPending: false; isSuccess: true; status: 'success'; } type MutationObserverResult = MutationObserverIdleResult | MutationObserverLoadingResult | MutationObserverErrorResult | MutationObserverSuccessResult; interface QueryClientConfig { queryCache?: QueryCache; mutationCache?: MutationCache; defaultOptions?: DefaultOptions; } interface DefaultOptions { queries?: OmitKeyof, 'suspense' | 'queryKey'>; mutations?: MutationObserverOptions; hydrate?: HydrateOptions['defaultOptions']; dehydrate?: DehydrateOptions; } interface CancelOptions { revert?: boolean; silent?: boolean; } interface SetDataOptions { updatedAt?: number; } type NotifyEventType = 'added' | 'removed' | 'updated' | 'observerAdded' | 'observerRemoved' | 'observerResultsUpdated' | 'observerOptionsUpdated'; interface NotifyEvent { type: NotifyEventType; } type TransformerFn = (data: any) => any; interface DehydrateOptions { serializeData?: TransformerFn; shouldDehydrateMutation?: (mutation: Mutation) => boolean; shouldDehydrateQuery?: (query: Query) => boolean; } interface HydrateOptions { defaultOptions?: { deserializeData?: TransformerFn; queries?: QueryOptions; mutations?: MutationOptions; }; } interface DehydratedMutation { mutationKey?: MutationKey; state: MutationState; meta?: MutationMeta; scope?: MutationScope; } interface DehydratedQuery { queryHash: string; queryKey: QueryKey; state: QueryState; promise?: Promise; meta?: QueryMeta; } interface DehydratedState { mutations: Array; queries: Array; } declare function defaultShouldDehydrateMutation(mutation: Mutation): boolean; declare function defaultShouldDehydrateQuery(query: Query): boolean; declare function dehydrate(client: QueryClient, options?: DehydrateOptions): DehydratedState; declare function hydrate(client: QueryClient, dehydratedState: unknown, options?: HydrateOptions): void; export { type NotifyOnChangeProps as $, type QueryKey as A, dataTagSymbol as B, CancelledError as C, type DehydrateOptions as D, type DataTag as E, type QueryFunction as F, type StaleTime as G, type HydrateOptions as H, type Enabled as I, type QueryPersister as J, type QueryFunctionContext as K, type InitialDataFunction as L, MutationCache as M, type NoInfer as N, type OmitKeyof as O, type PlaceholderDataFunction as P, QueryCache as Q, type Register as R, type SkipToken as S, type QueriesPlaceholderDataFunction as T, type Updater as U, type QueryKeyHashFunction as V, type GetPreviousPageParamFunction as W, type GetNextPageParamFunction as X, type InfiniteData as Y, type QueryMeta as Z, type NetworkMode as _, type QueryCacheNotifyEvent as a, type FetchContext as a$, type QueryOptions as a0, type InitialPageParam as a1, type InfiniteQueryPageParamsOptions as a2, type ThrowOnError as a3, type QueryObserverOptions as a4, type WithRequired as a5, type Optional as a6, type DefaultedQueryObserverOptions as a7, type InfiniteQueryObserverOptions as a8, type DefaultedInfiniteQueryObserverOptions as a9, type InfiniteQueryObserverRefetchErrorResult as aA, type InfiniteQueryObserverSuccessResult as aB, type DefinedInfiniteQueryObserverResult as aC, type InfiniteQueryObserverResult as aD, type MutationKey as aE, type MutationStatus as aF, type MutationScope as aG, type MutationMeta as aH, type MutationFunction as aI, type MutationOptions as aJ, type MutationObserverOptions as aK, type MutateOptions as aL, type MutateFunction as aM, type MutationObserverBaseResult as aN, type MutationObserverIdleResult as aO, type MutationObserverLoadingResult as aP, type MutationObserverErrorResult as aQ, type MutationObserverSuccessResult as aR, type MutationObserverResult as aS, type QueryClientConfig as aT, type DefaultOptions as aU, type CancelOptions as aV, type SetDataOptions as aW, type NotifyEventType as aX, type NotifyEvent as aY, type QueryBehavior as aZ, type NotifyOptions as a_, type FetchQueryOptions as aa, type EnsureQueryDataOptions as ab, type EnsureInfiniteQueryDataOptions as ac, type FetchInfiniteQueryOptions as ad, type ResultOptions as ae, type RefetchOptions as af, type InvalidateQueryFilters as ag, type RefetchQueryFilters as ah, type InvalidateOptions as ai, type ResetOptions as aj, type FetchNextPageOptions as ak, type FetchPreviousPageOptions as al, type QueryStatus as am, type FetchStatus as an, type QueryObserverBaseResult as ao, type QueryObserverPendingResult as ap, type QueryObserverLoadingResult as aq, type QueryObserverLoadingErrorResult as ar, type QueryObserverRefetchErrorResult as as, type QueryObserverSuccessResult as at, type DefinedQueryObserverResult as au, type QueryObserverResult as av, type InfiniteQueryObserverBaseResult as aw, type InfiniteQueryObserverPendingResult as ax, type InfiniteQueryObserverLoadingResult as ay, type InfiniteQueryObserverLoadingErrorResult as az, QueryClient as b, type FetchDirection as b0, type FetchMeta as b1, type FetchOptions as b2, type Action$1 as b3, type SetStateOptions as b4, fetchState as b5, type QueryTypeFilter as b6, noop as b7, functionalUpdate as b8, isValidTimeout as b9, timeUntilStale as ba, resolveStaleTime as bb, resolveEnabled as bc, hashQueryKeyByOptions as bd, partialMatchKey as be, shallowEqualObjects as bf, isPlainArray as bg, isPlainObject as bh, sleep as bi, replaceData as bj, addToEnd as bk, addToStart as bl, ensureQueryFn as bm, type QueryStore as bn, type Action as bo, getDefaultState as bp, type Retryer as bq, type RetryValue as br, type RetryDelayValue as bs, canFetch as bt, createRetryer as bu, QueryObserver as c, type MutationCacheNotifyEvent as d, MutationObserver as e, matchMutation as f, type MutationFilters as g, hashKey as h, isServer as i, type QueryFilters as j, keepPreviousData as k, isCancelledError as l, matchQuery as m, dehydrate as n, hydrate as o, defaultShouldDehydrateQuery as p, defaultShouldDehydrateMutation as q, replaceEqualDeep as r, skipToken as s, type QueryState as t, Query as u, type MutationState as v, Mutation as w, type DehydratedState as x, type Override as y, type DefaultError as z };