useProject
Datalayer Core / useProject
Function: useProject()
useProject(
uid): {data:ProjectData|undefined;dataUpdatedAt:number;error:Error;errorUpdateCount:number;errorUpdatedAt:number;failureCount:number;failureReason:Error|null;fetchStatus:FetchStatus;isEnabled:boolean;isError:true;isFetched:boolean;isFetchedAfterMount:boolean;isFetching:boolean;isInitialLoading:boolean;isLoading:false;isLoadingError:false;isPaused:boolean;isPending:false;isPlaceholderData:false;isRefetchError:true;isRefetching:boolean;isStale:boolean;isSuccess:false;promise:Promise<IAnySpace>;refetch: (options?) =>Promise<QueryObserverResult<IAnySpace,Error>>;status:"error"; } | {data:ProjectData|undefined;dataUpdatedAt:number;error:null;errorUpdateCount:number;errorUpdatedAt:number;failureCount:number;failureReason:Error|null;fetchStatus:FetchStatus;isEnabled:boolean;isError:false;isFetched:boolean;isFetchedAfterMount:boolean;isFetching:boolean;isInitialLoading:boolean;isLoading:false;isLoadingError:false;isPaused:boolean;isPending:false;isPlaceholderData:false;isRefetchError:false;isRefetching:boolean;isStale:boolean;isSuccess:true;promise:Promise<IAnySpace>;refetch: (options?) =>Promise<QueryObserverResult<IAnySpace,Error>>;status:"success"; } | {data:ProjectData|undefined;dataUpdatedAt:number;error:Error;errorUpdateCount:number;errorUpdatedAt:number;failureCount:number;failureReason:Error|null;fetchStatus:FetchStatus;isEnabled:boolean;isError:true;isFetched:boolean;isFetchedAfterMount:boolean;isFetching:boolean;isInitialLoading:boolean;isLoading:false;isLoadingError:true;isPaused:boolean;isPending:false;isPlaceholderData:false;isRefetchError:false;isRefetching:boolean;isStale:boolean;isSuccess:false;promise:Promise<IAnySpace>;refetch: (options?) =>Promise<QueryObserverResult<IAnySpace,Error>>;status:"error"; } | {data:ProjectData|undefined;dataUpdatedAt:number;error:null;errorUpdateCount:number;errorUpdatedAt:number;failureCount:number;failureReason:Error|null;fetchStatus:FetchStatus;isEnabled:boolean;isError:false;isFetched:boolean;isFetchedAfterMount:boolean;isFetching:boolean;isInitialLoading:boolean;isLoading:true;isLoadingError:false;isPaused:boolean;isPending:true;isPlaceholderData:false;isRefetchError:false;isRefetching:boolean;isStale:boolean;isSuccess:false;promise:Promise<IAnySpace>;refetch: (options?) =>Promise<QueryObserverResult<IAnySpace,Error>>;status:"pending"; } | {data:ProjectData|undefined;dataUpdatedAt:number;error:null;errorUpdateCount:number;errorUpdatedAt:number;failureCount:number;failureReason:Error|null;fetchStatus:FetchStatus;isEnabled:boolean;isError:false;isFetched:boolean;isFetchedAfterMount:boolean;isFetching:boolean;isInitialLoading:boolean;isLoading:boolean;isLoadingError:false;isPaused:boolean;isPending:true;isPlaceholderData:false;isRefetchError:false;isRefetching:boolean;isStale:boolean;isSuccess:false;promise:Promise<IAnySpace>;refetch: (options?) =>Promise<QueryObserverResult<IAnySpace,Error>>;status:"pending"; } | {data:ProjectData|undefined;dataUpdatedAt:number;error:null;errorUpdateCount:number;errorUpdatedAt:number;failureCount:number;failureReason:Error|null;fetchStatus:FetchStatus;isEnabled:boolean;isError:false;isFetched:boolean;isFetchedAfterMount:boolean;isFetching:boolean;isInitialLoading:boolean;isLoading:false;isLoadingError:false;isPaused:boolean;isPending:false;isPlaceholderData:true;isRefetchError:false;isRefetching:boolean;isStale:boolean;isSuccess:true;promise:Promise<IAnySpace>;refetch: (options?) =>Promise<QueryObserverResult<IAnySpace,Error>>;status:"success"; }
Defined in: src/hooks/useProjects.ts:96
Hook to fetch a single project by UID.
Parameters
uid
string | undefined
Returns
Type Literal
{ data: ProjectData | undefined; dataUpdatedAt: number; error: Error; errorUpdateCount: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; fetchStatus: FetchStatus; isEnabled: boolean; isError: true; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isLoading: false; isLoadingError: false; isPaused: boolean; isPending: false; isPlaceholderData: false; isRefetchError: true; isRefetching: boolean; isStale: boolean; isSuccess: false; promise: Promise<IAnySpace>; refetch: (options?) => Promise<QueryObserverResult<IAnySpace, Error>>; status: "error"; }
data
data:
ProjectData|undefined=project
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
error
error:
Error
The error object for the query, if an error was thrown.
- Defaults to
null.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
errorUpdatedAt
errorUpdatedAt:
number
The timestamp for when the query most recently returned the status as "error".
failureCount
failureCount:
number
The failure count for the query.
- Incremented every time the query fails.
- Reset to
0when the query succeeds.
failureReason
failureReason:
Error|null
The failure reason for the query retry.
- Reset to
nullwhen the query succeeds.
fetchStatus
fetchStatus:
FetchStatus
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
isError
isError:
true
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isFetched
isFetched:
boolean
Will be true if the query has been fetched.
isFetchedAfterMount
isFetchedAfterMount:
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.
isFetching
isFetching:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
truewhenever thequeryFnis executing, which includes initialpendingas well as background refetch.
isInitialLoading
isInitialLoading:
boolean
Deprecated
isInitialLoading is being deprecated in favor of isLoading
and will be removed in the next major version.
isLoading
isLoading:
false
Is true whenever the first fetch for a query is in-flight.
- Is the same as
isFetching && isPending.
isLoadingError
isLoadingError:
false
Will be true if the query failed while fetching for the first time.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
isPending
isPending:
false
Will be pending if there's no cached data and no query attempt was finished yet.
isPlaceholderData
isPlaceholderData:
false
Will be true if the data shown is the placeholder data.
isRefetchError
isRefetchError:
true
Will be true if the query failed while refetching.
isRefetching
isRefetching:
boolean
Is true whenever a background refetch is in-flight, which does not include initial pending.
- Is the same as
isFetching && !isPending.
isStale
isStale:
boolean
Will be true if the data in the cache is invalidated or if the data is older than the given staleTime.
isSuccess
isSuccess:
false
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.
promise
promise:
Promise<IAnySpace>
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>
</>
)
}
refetch
refetch: (
options?) =>Promise<QueryObserverResult<IAnySpace,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<IAnySpace, Error>>
status
status:
"error"
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.
Type Literal
{ data: ProjectData | undefined; dataUpdatedAt: number; error: null; errorUpdateCount: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; fetchStatus: FetchStatus; isEnabled: boolean; isError: false; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isLoading: false; isLoadingError: false; isPaused: boolean; isPending: false; isPlaceholderData: false; isRefetchError: false; isRefetching: boolean; isStale: boolean; isSuccess: true; promise: Promise<IAnySpace>; refetch: (options?) => Promise<QueryObserverResult<IAnySpace, Error>>; status: "success"; }
data
data:
ProjectData|undefined=project
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
error
error:
null
The error object for the query, if an error was thrown.
- Defaults to
null.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
errorUpdatedAt
errorUpdatedAt:
number
The timestamp for when the query most recently returned the status as "error".
failureCount
failureCount:
number
The failure count for the query.
- Incremented every time the query fails.
- Reset to
0when the query succeeds.
failureReason
failureReason:
Error|null
The failure reason for the query retry.
- Reset to
nullwhen the query succeeds.
fetchStatus
fetchStatus:
FetchStatus
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
isError
isError:
false
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isFetched
isFetched:
boolean
Will be true if the query has been fetched.
isFetchedAfterMount
isFetchedAfterMount:
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.
isFetching
isFetching:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
truewhenever thequeryFnis executing, which includes initialpendingas well as background refetch.
isInitialLoading
isInitialLoading:
boolean
Deprecated
isInitialLoading is being deprecated in favor of isLoading
and will be removed in the next major version.
isLoading
isLoading:
false
Is true whenever the first fetch for a query is in-flight.
- Is the same as
isFetching && isPending.
isLoadingError
isLoadingError:
false
Will be true if the query failed while fetching for the first time.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
isPending
isPending:
false
Will be pending if there's no cached data and no query attempt was finished yet.
isPlaceholderData
isPlaceholderData:
false
Will be true if the data shown is the placeholder data.
isRefetchError
isRefetchError:
false
Will be true if the query failed while refetching.
isRefetching
isRefetching:
boolean
Is true whenever a background refetch is in-flight, which does not include initial pending.
- Is the same as
isFetching && !isPending.
isStale
isStale:
boolean
Will be true if the data in the cache is invalidated or if the data is older than the given staleTime.
isSuccess
isSuccess:
true
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.
promise
promise:
Promise<IAnySpace>
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>
</>
)
}
refetch
refetch: (
options?) =>Promise<QueryObserverResult<IAnySpace,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<IAnySpace, Error>>
status
status:
"success"
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.
Type Literal
{ data: ProjectData | undefined; dataUpdatedAt: number; error: Error; errorUpdateCount: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; fetchStatus: FetchStatus; isEnabled: boolean; isError: true; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isLoading: false; isLoadingError: true; isPaused: boolean; isPending: false; isPlaceholderData: false; isRefetchError: false; isRefetching: boolean; isStale: boolean; isSuccess: false; promise: Promise<IAnySpace>; refetch: (options?) => Promise<QueryObserverResult<IAnySpace, Error>>; status: "error"; }
data
data:
ProjectData|undefined=project
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
error
error:
Error
The error object for the query, if an error was thrown.
- Defaults to
null.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
errorUpdatedAt
errorUpdatedAt:
number
The timestamp for when the query most recently returned the status as "error".
failureCount
failureCount:
number
The failure count for the query.
- Incremented every time the query fails.
- Reset to
0when the query succeeds.
failureReason
failureReason:
Error|null
The failure reason for the query retry.
- Reset to
nullwhen the query succeeds.
fetchStatus
fetchStatus:
FetchStatus
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
isError
isError:
true
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isFetched
isFetched:
boolean
Will be true if the query has been fetched.
isFetchedAfterMount
isFetchedAfterMount:
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.
isFetching
isFetching:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
truewhenever thequeryFnis executing, which includes initialpendingas well as background refetch.
isInitialLoading
isInitialLoading:
boolean
Deprecated
isInitialLoading is being deprecated in favor of isLoading
and will be removed in the next major version.
isLoading
isLoading:
false
Is true whenever the first fetch for a query is in-flight.
- Is the same as
isFetching && isPending.
isLoadingError
isLoadingError:
true
Will be true if the query failed while fetching for the first time.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
isPending
isPending:
false
Will be pending if there's no cached data and no query attempt was finished yet.
isPlaceholderData
isPlaceholderData:
false
Will be true if the data shown is the placeholder data.
isRefetchError
isRefetchError:
false
Will be true if the query failed while refetching.
isRefetching
isRefetching:
boolean
Is true whenever a background refetch is in-flight, which does not include initial pending.
- Is the same as
isFetching && !isPending.
isStale
isStale:
boolean
Will be true if the data in the cache is invalidated or if the data is older than the given staleTime.
isSuccess
isSuccess:
false
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.
promise
promise:
Promise<IAnySpace>
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>
</>
)
}
refetch
refetch: (
options?) =>Promise<QueryObserverResult<IAnySpace,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<IAnySpace, Error>>
status
status:
"error"
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.
Type Literal
{ data: ProjectData | undefined; dataUpdatedAt: number; error: null; errorUpdateCount: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; fetchStatus: FetchStatus; isEnabled: boolean; isError: false; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isLoading: true; isLoadingError: false; isPaused: boolean; isPending: true; isPlaceholderData: false; isRefetchError: false; isRefetching: boolean; isStale: boolean; isSuccess: false; promise: Promise<IAnySpace>; refetch: (options?) => Promise<QueryObserverResult<IAnySpace, Error>>; status: "pending"; }
data
data:
ProjectData|undefined=project
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
error
error:
null
The error object for the query, if an error was thrown.
- Defaults to
null.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
errorUpdatedAt
errorUpdatedAt:
number
The timestamp for when the query most recently returned the status as "error".
failureCount
failureCount:
number
The failure count for the query.
- Incremented every time the query fails.
- Reset to
0when the query succeeds.
failureReason
failureReason:
Error|null
The failure reason for the query retry.
- Reset to
nullwhen the query succeeds.
fetchStatus
fetchStatus:
FetchStatus
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
isError
isError:
false
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isFetched
isFetched:
boolean
Will be true if the query has been fetched.
isFetchedAfterMount
isFetchedAfterMount:
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.
isFetching
isFetching:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
truewhenever thequeryFnis executing, which includes initialpendingas well as background refetch.
isInitialLoading
isInitialLoading:
boolean
Deprecated
isInitialLoading is being deprecated in favor of isLoading
and will be removed in the next major version.
isLoading
isLoading:
true
Is true whenever the first fetch for a query is in-flight.
- Is the same as
isFetching && isPending.
isLoadingError
isLoadingError:
false
Will be true if the query failed while fetching for the first time.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
isPending
isPending:
true
Will be pending if there's no cached data and no query attempt was finished yet.
isPlaceholderData
isPlaceholderData:
false
Will be true if the data shown is the placeholder data.
isRefetchError
isRefetchError:
false
Will be true if the query failed while refetching.
isRefetching
isRefetching:
boolean
Is true whenever a background refetch is in-flight, which does not include initial pending.
- Is the same as
isFetching && !isPending.
isStale
isStale:
boolean
Will be true if the data in the cache is invalidated or if the data is older than the given staleTime.
isSuccess
isSuccess:
false
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.
promise
promise:
Promise<IAnySpace>
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>
</>
)
}
refetch
refetch: (
options?) =>Promise<QueryObserverResult<IAnySpace,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<IAnySpace, Error>>
status
status:
"pending"
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.
Type Literal
{ data: ProjectData | undefined; dataUpdatedAt: number; error: null; errorUpdateCount: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; fetchStatus: FetchStatus; isEnabled: boolean; isError: false; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isLoading: boolean; isLoadingError: false; isPaused: boolean; isPending: true; isPlaceholderData: false; isRefetchError: false; isRefetching: boolean; isStale: boolean; isSuccess: false; promise: Promise<IAnySpace>; refetch: (options?) => Promise<QueryObserverResult<IAnySpace, Error>>; status: "pending"; }
data
data:
ProjectData|undefined=project
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
error
error:
null
The error object for the query, if an error was thrown.
- Defaults to
null.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
errorUpdatedAt
errorUpdatedAt:
number
The timestamp for when the query most recently returned the status as "error".
failureCount
failureCount:
number
The failure count for the query.
- Incremented every time the query fails.
- Reset to
0when the query succeeds.
failureReason
failureReason:
Error|null
The failure reason for the query retry.
- Reset to
nullwhen the query succeeds.
fetchStatus
fetchStatus:
FetchStatus
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
isError
isError:
false
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isFetched
isFetched:
boolean
Will be true if the query has been fetched.
isFetchedAfterMount
isFetchedAfterMount:
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.
isFetching
isFetching:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
truewhenever thequeryFnis executing, which includes initialpendingas well as background refetch.
isInitialLoading
isInitialLoading:
boolean
Deprecated
isInitialLoading is being deprecated in favor of isLoading
and will be removed in the next major version.
isLoading
isLoading:
boolean
Is true whenever the first fetch for a query is in-flight.
- Is the same as
isFetching && isPending.
isLoadingError
isLoadingError:
false
Will be true if the query failed while fetching for the first time.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
isPending
isPending:
true
Will be pending if there's no cached data and no query attempt was finished yet.
isPlaceholderData
isPlaceholderData:
false
Will be true if the data shown is the placeholder data.
isRefetchError
isRefetchError:
false
Will be true if the query failed while refetching.
isRefetching
isRefetching:
boolean
Is true whenever a background refetch is in-flight, which does not include initial pending.
- Is the same as
isFetching && !isPending.
isStale
isStale:
boolean
Will be true if the data in the cache is invalidated or if the data is older than the given staleTime.
isSuccess
isSuccess:
false
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.
promise
promise:
Promise<IAnySpace>
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>
</>
)
}
refetch
refetch: (
options?) =>Promise<QueryObserverResult<IAnySpace,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<IAnySpace, Error>>
status
status:
"pending"
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.
Type Literal
{ data: ProjectData | undefined; dataUpdatedAt: number; error: null; errorUpdateCount: number; errorUpdatedAt: number; failureCount: number; failureReason: Error | null; fetchStatus: FetchStatus; isEnabled: boolean; isError: false; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isLoading: false; isLoadingError: false; isPaused: boolean; isPending: false; isPlaceholderData: true; isRefetchError: false; isRefetching: boolean; isStale: boolean; isSuccess: true; promise: Promise<IAnySpace>; refetch: (options?) => Promise<QueryObserverResult<IAnySpace, Error>>; status: "success"; }
data
data:
ProjectData|undefined=project
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
error
error:
null
The error object for the query, if an error was thrown.
- Defaults to
null.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
errorUpdatedAt
errorUpdatedAt:
number
The timestamp for when the query most recently returned the status as "error".
failureCount
failureCount:
number
The failure count for the query.
- Incremented every time the query fails.
- Reset to
0when the query succeeds.
failureReason
failureReason:
Error|null
The failure reason for the query retry.
- Reset to
nullwhen the query succeeds.
fetchStatus
fetchStatus:
FetchStatus
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
isError
isError:
false
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isFetched
isFetched:
boolean
Will be true if the query has been fetched.
isFetchedAfterMount
isFetchedAfterMount:
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.
isFetching
isFetching:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
truewhenever thequeryFnis executing, which includes initialpendingas well as background refetch.
isInitialLoading
isInitialLoading:
boolean
Deprecated
isInitialLoading is being deprecated in favor of isLoading
and will be removed in the next major version.
isLoading
isLoading:
false
Is true whenever the first fetch for a query is in-flight.
- Is the same as
isFetching && isPending.
isLoadingError
isLoadingError:
false
Will be true if the query failed while fetching for the first time.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
isPending
isPending:
false
Will be pending if there's no cached data and no query attempt was finished yet.
isPlaceholderData
isPlaceholderData:
true
Will be true if the data shown is the placeholder data.
isRefetchError
isRefetchError:
false
Will be true if the query failed while refetching.
isRefetching
isRefetching:
boolean
Is true whenever a background refetch is in-flight, which does not include initial pending.
- Is the same as
isFetching && !isPending.
isStale
isStale:
boolean
Will be true if the data in the cache is invalidated or if the data is older than the given staleTime.
isSuccess
isSuccess:
true
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.
promise
promise:
Promise<IAnySpace>
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>
</>
)
}
refetch
refetch: (
options?) =>Promise<QueryObserverResult<IAnySpace,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<IAnySpace, Error>>
status
status:
"success"
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.