Interface: QueryObserverPlaceholderResult<TData, TError>#
Defined in: packages/query-core/src/types.ts:876
Extends#
QueryObserverBaseResult<TData,TError>
Type Parameters#
TData#
TData = unknown
TError#
TError = DefaultError
Properties#
data#
data: TData;
Defined in: packages/query-core/src/types.ts:880
The last successfully resolved data for the query.
Overrides#
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#
QueryObserverBaseResult.dataUpdatedAt
error#
error: null;
Defined in: packages/query-core/src/types.ts:882
The error object for the query, if an error was thrown.
- Defaults to
null.
Overrides#
errorUpdateCount#
errorUpdateCount: number;
Defined in: packages/query-core/src/types.ts:655
The sum of all errors.
Inherited from#
QueryObserverBaseResult.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#
QueryObserverBaseResult.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
0when the query succeeds.
Inherited from#
QueryObserverBaseResult.failureCount
failureReason#
failureReason: TError | null;
Defined in: packages/query-core/src/types.ts:651
The failure reason for the query retry.
- Reset to
nullwhen the query succeeds.
Inherited from#
QueryObserverBaseResult.failureReason
fetchStatus#
fetchStatus: FetchStatus;
Defined in: packages/query-core/src/types.ts:745
The fetch status of the query.
fetching: Istruewhenever the queryFn is executing, which includes initialpendingas well as background refetch.paused: The query wanted to fetch, but has beenpaused.idle: The query is not fetching.- See Network Mode for more information.
Inherited from#
QueryObserverBaseResult.fetchStatus
isEnabled#
isEnabled: boolean;
Defined in: packages/query-core/src/types.ts:723
true if this observer is enabled, false otherwise.
Inherited from#
QueryObserverBaseResult.isEnabled
isError#
isError: false;
Defined in: packages/query-core/src/types.ts:881
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
Overrides#
QueryObserverBaseResult.isError
isFetched#
isFetched: boolean;
Defined in: packages/query-core/src/types.ts:664
Will be true if the query has been fetched.
Inherited from#
QueryObserverBaseResult.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#
QueryObserverBaseResult.isFetchedAfterMount
isFetching#
isFetching: boolean;
Defined in: packages/query-core/src/types.ts:674
A derived boolean from the fetchStatus variable, provided for convenience.
truewhenever thequeryFnis executing, which includes initialpendingas well as background refetch.
Inherited from#
QueryObserverBaseResult.isFetching
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#
QueryObserverBaseResult.isInitialLoading
isLoading#
isLoading: false;
Defined in: packages/query-core/src/types.ts:884
Is true whenever the first fetch for a query is in-flight.
- Is the same as
isFetching && isPending.
Overrides#
QueryObserverBaseResult.isLoading
isLoadingError#
isLoadingError: false;
Defined in: packages/query-core/src/types.ts:885
Will be true if the query failed while fetching for the first time.
Overrides#
QueryObserverBaseResult.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#
QueryObserverBaseResult.isPaused
isPending#
isPending: false;
Defined in: packages/query-core/src/types.ts:883
Will be pending if there's no cached data and no query attempt was finished yet.
Overrides#
QueryObserverBaseResult.isPending
isPlaceholderData#
isPlaceholderData: true;
Defined in: packages/query-core/src/types.ts:888
Will be true if the data shown is the placeholder data.
Overrides#
QueryObserverBaseResult.isPlaceholderData
isRefetchError#
isRefetchError: false;
Defined in: packages/query-core/src/types.ts:886
Will be true if the query failed while refetching.
Overrides#
QueryObserverBaseResult.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#
QueryObserverBaseResult.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#
QueryObserverBaseResult.isStale
isSuccess#
isSuccess: true;
Defined in: packages/query-core/src/types.ts:887
A derived boolean from the status variable, provided for convenience.
trueif the query has received a response with no errors and is ready to display its data.
Overrides#
QueryObserverBaseResult.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#
QueryObserverBaseResult.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?#
Returns#
Promise<QueryObserverResult<TData, TError>>
Inherited from#
QueryObserverBaseResult.refetch
status#
status: "success";
Defined in: packages/query-core/src/types.ts:889
The status of the query.
- Will be:
pendingif there's no cached data and no query attempt was finished yet.errorif the query attempt resulted in an error.successif the query has received a response with no errors and is ready to display its data.