Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

InfiniteQueryObserverPendingResult.md

664 lines17.3 KB

Interface: InfiniteQueryObserverPendingResult<TData, TError>

Defined in: packages/query-core/src/types.ts:948

Extends

Type Parameters

TData

TData = unknown

TError

TError = DefaultError

Properties

data

data: undefined;

Defined in: packages/query-core/src/types.ts:952

The last successfully resolved data for the query.

Overrides

InfiniteQueryObserverBaseResult.data


dataUpdatedAt

dataUpdatedAt: number;

Defined in: packages/query-core/src/types.ts:631

The timestamp for when the query most recently returned the status as "success".

Inherited from

InfiniteQueryObserverBaseResult.dataUpdatedAt


error

error: null;

Defined in: packages/query-core/src/types.ts:953

The error object for the query, if an error was thrown.

  • Defaults to null.

Overrides

InfiniteQueryObserverBaseResult.error


errorUpdateCount

errorUpdateCount: number;

Defined in: packages/query-core/src/types.ts:655

The sum of all errors.

Inherited from

InfiniteQueryObserverBaseResult.errorUpdateCount


errorUpdatedAt

errorUpdatedAt: number;

Defined in: packages/query-core/src/types.ts:640

The timestamp for when the query most recently returned the status as "error".

Inherited from

InfiniteQueryObserverBaseResult.errorUpdatedAt


failureCount

failureCount: number;

Defined in: packages/query-core/src/types.ts:646

The failure count for the query.

  • Incremented every time the query fails.
  • Reset to 0 when the query succeeds.

Inherited from

InfiniteQueryObserverBaseResult.failureCount


failureReason

failureReason: TError | null;

Defined in: packages/query-core/src/types.ts:651

The failure reason for the query retry.

  • Reset to null when the query succeeds.

Inherited from

InfiniteQueryObserverBaseResult.failureReason


fetchNextPage()

fetchNextPage: (options?) => Promise<InfiniteQueryObserverResult<TData, TError>>;

Defined in: packages/query-core/src/types.ts:913

This function allows you to fetch the next "page" of results.

Parameters

options?

FetchNextPageOptions

Returns

Promise<InfiniteQueryObserverResult<TData, TError>>

Inherited from

InfiniteQueryObserverBaseResult.fetchNextPage


fetchPreviousPage()

fetchPreviousPage: (options?) => Promise<InfiniteQueryObserverResult<TData, TError>>;

Defined in: packages/query-core/src/types.ts:919

This function allows you to fetch the previous "page" of results.

Parameters

options?

FetchPreviousPageOptions

Returns

Promise<InfiniteQueryObserverResult<TData, TError>>

Inherited from

InfiniteQueryObserverBaseResult.fetchPreviousPage


fetchStatus

fetchStatus: FetchStatus;

Defined in: packages/query-core/src/types.ts:745

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 for more information.

Inherited from

InfiniteQueryObserverBaseResult.fetchStatus


hasNextPage

hasNextPage: boolean;

Defined in: packages/query-core/src/types.ts:925

Will be true if there is a next page to be fetched (known via the getNextPageParam option).

Inherited from

InfiniteQueryObserverBaseResult.hasNextPage


hasPreviousPage

hasPreviousPage: boolean;

Defined in: packages/query-core/src/types.ts:929

Will be true if there is a previous page to be fetched (known via the getPreviousPageParam option).

Inherited from

InfiniteQueryObserverBaseResult.hasPreviousPage


isEnabled

isEnabled: boolean;

Defined in: packages/query-core/src/types.ts:723

true if this observer is enabled, false otherwise.

Inherited from

InfiniteQueryObserverBaseResult.isEnabled


isError

isError: false;

Defined in: packages/query-core/src/types.ts:954

A derived boolean from the status variable, provided for convenience.

  • true if the query attempt resulted in an error.

Overrides

InfiniteQueryObserverBaseResult.isError


isFetched

isFetched: boolean;

Defined in: packages/query-core/src/types.ts:664

Will be true if the query has been fetched.

Inherited from

InfiniteQueryObserverBaseResult.isFetched


isFetchedAfterMount

isFetchedAfterMount: boolean;

Defined in: packages/query-core/src/types.ts:669

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.

Inherited from

InfiniteQueryObserverBaseResult.isFetchedAfterMount


isFetching

isFetching: boolean;

Defined in: packages/query-core/src/types.ts:674

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.

Inherited from

InfiniteQueryObserverBaseResult.isFetching


isFetchingNextPage

isFetchingNextPage: boolean;

Defined in: packages/query-core/src/types.ts:937

Will be true while fetching the next page with fetchNextPage.

Inherited from

InfiniteQueryObserverBaseResult.isFetchingNextPage


isFetchingPreviousPage

isFetchingPreviousPage: boolean;

Defined in: packages/query-core/src/types.ts:945

Will be true while fetching the previous page with fetchPreviousPage.

Inherited from

InfiniteQueryObserverBaseResult.isFetchingPreviousPage


isFetchNextPageError

isFetchNextPageError: false;

Defined in: packages/query-core/src/types.ts:958

Will be true if the query failed while fetching the next page.

Overrides

InfiniteQueryObserverBaseResult.isFetchNextPageError


isFetchPreviousPageError

isFetchPreviousPageError: false;

Defined in: packages/query-core/src/types.ts:959

Will be true if the query failed while fetching the previous page.

Overrides

InfiniteQueryObserverBaseResult.isFetchPreviousPageError


isInitialLoading

isInitialLoading: boolean;

Defined in: packages/query-core/src/types.ts:692

Deprecated

isInitialLoading is being deprecated in favor of isLoading and will be removed in the next major version.

Inherited from

InfiniteQueryObserverBaseResult.isInitialLoading


isLoading

isLoading: boolean;

Defined in: packages/query-core/src/types.ts:679

Is true whenever the first fetch for a query is in-flight.

  • Is the same as isFetching && isPending.

Inherited from

InfiniteQueryObserverBaseResult.isLoading


isLoadingError

isLoadingError: false;

Defined in: packages/query-core/src/types.ts:956

Will be true if the query failed while fetching for the first time.

Overrides

InfiniteQueryObserverBaseResult.isLoadingError


isPaused

isPaused: boolean;

Defined in: packages/query-core/src/types.ts:697

A derived boolean from the fetchStatus variable, provided for convenience.

  • The query wanted to fetch, but has been paused.

Inherited from

InfiniteQueryObserverBaseResult.isPaused


isPending

isPending: true;

Defined in: packages/query-core/src/types.ts:955

Will be pending if there's no cached data and no query attempt was finished yet.

Overrides

InfiniteQueryObserverBaseResult.isPending


isPlaceholderData

isPlaceholderData: false;

Defined in: packages/query-core/src/types.ts:961

Will be true if the data shown is the placeholder data.

Overrides

InfiniteQueryObserverBaseResult.isPlaceholderData


isRefetchError

isRefetchError: false;

Defined in: packages/query-core/src/types.ts:957

Will be true if the query failed while refetching.

Overrides

InfiniteQueryObserverBaseResult.isRefetchError


isRefetching

isRefetching: boolean;

Defined in: packages/query-core/src/types.ts:710

Is true whenever a background refetch is in-flight, which does not include initial pending.

  • Is the same as isFetching && !isPending.

Inherited from

InfiniteQueryObserverBaseResult.isRefetching


isStale

isStale: boolean;

Defined in: packages/query-core/src/types.ts:714

Will be true if the data in the cache is invalidated or if the data is older than the given staleTime.

Inherited from

InfiniteQueryObserverBaseResult.isStale


isSuccess

isSuccess: false;

Defined in: packages/query-core/src/types.ts:960

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.

Overrides

InfiniteQueryObserverBaseResult.isSuccess


promise

promise: Promise<TData>;

Defined in: packages/query-core/src/types.ts:794

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

const client = new QueryClient({
  defaultOptions: {
    queries: {
      experimental_prefetchInRender: true,
    },
  },
})

Usage

import { useQuery } from '@tanstack/react-query'
import React from 'react'
import { fetchTodos, type Todo } from './api'

function TodoList({ query }: { query: UseQueryResult<Todo[], Error> }) {
  const data = React.use(query.promise)

  return (
    <ul>
      {data.map(todo => (
        <li key={todo.id}>{todo.title}</li>
      ))}
    </ul>
  )
}

export function App() {
  const query = useQuery({ queryKey: ['todos'], queryFn: fetchTodos })

  return (
    <>
      <h1>Todos</h1>
      <React.Suspense fallback={<div>Loading...</div>}>
        <TodoList query={query} />
      </React.Suspense>
    </>
  )
}

Inherited from

InfiniteQueryObserverBaseResult.promise


refetch()

refetch: (options?) => Promise<QueryObserverResult<TData, TError>>;

Defined in: packages/query-core/src/types.ts:727

A function to manually refetch the query.

Parameters

options?

RefetchOptions

Returns

Promise<QueryObserverResult<TData, TError>>

Inherited from

InfiniteQueryObserverBaseResult.refetch


status

status: "pending";

Defined in: packages/query-core/src/types.ts:962

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.

Overrides

InfiniteQueryObserverBaseResult.status