web / lib/hooks/use-data-export
lib/hooks/use-data-export
React Query hooks for data export functionality.
Provides hooks for requesting data exports, checking status, and downloading.
Variables
dataExportKeys
constdataExportKeys:object
Query key for data exports.
Type Declaration
all
all: readonly [
"data-exports"]
list()
list: () => readonly [
"data-exports","list"]
Returns
readonly ["data-exports", "list"]
latest()
latest: () => readonly [
"data-exports","latest"]
Returns
readonly ["data-exports", "latest"]
Functions
useDataExportsQuery()
useDataExportsQuery():
UseQueryResult<ExportListResponse,Error>
Hook to fetch the user’s data exports.
Returns
UseQueryResult<ExportListResponse, Error>
useLatestExportQuery()
useLatestExportQuery():
{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: [ExportListResponse](../types/data-export-api.md#exportlistresponse); error: Error; isError: true; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: true; isSuccess: false; isPlaceholderData: false; status: "error"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }|{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: [ExportListResponse](../types/data-export-api.md#exportlistresponse); error: null; isError: false; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: false; isSuccess: true; isPlaceholderData: false; status: "success"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }|{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: undefined; error: Error; isError: true; isPending: false; isLoading: false; isLoadingError: true; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "error"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }|{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: undefined; error: null; isError: false; isPending: true; isLoading: true; isLoadingError: false; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "pending"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }|{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isLoading: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: undefined; error: null; isError: false; isPending: true; isLoadingError: false; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "pending"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }|{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: [ExportListResponse](../types/data-export-api.md#exportlistresponse); isError: false; error: null; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: false; isSuccess: true; isPlaceholderData: true; status: "success"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }
Hook to get the most recent/relevant export.
Returns
{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: [ExportListResponse](../types/data-export-api.md#exportlistresponse); error: Error; isError: true; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: true; isSuccess: false; isPlaceholderData: false; status: "error"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
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.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
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.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
refetch()
refetch: (
options?) =>Promise<QueryObserverResult<ExportListResponse,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<ExportListResponse, Error>>
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.
promise
promise:
Promise<ExportListResponse>
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>
</>
)
}data
data:
ExportListResponse
The last successfully resolved data for the query.
error
error:
Error
The error object for the query, if an error was thrown.
- Defaults to
null.
isError
isError:
true
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isPending
isPending:
false
Will be pending if there’s no cached data and no query attempt was finished yet.
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.
isRefetchError
isRefetchError:
true
Will be true if the query failed while refetching.
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.
isPlaceholderData
isPlaceholderData:
false
Will be true if the data shown is the placeholder data.
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.
latestExport
latestExport:
DataExport|undefined
{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: [ExportListResponse](../types/data-export-api.md#exportlistresponse); error: null; isError: false; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: false; isSuccess: true; isPlaceholderData: false; status: "success"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
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.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
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.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
refetch()
refetch: (
options?) =>Promise<QueryObserverResult<ExportListResponse,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<ExportListResponse, Error>>
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.
promise
promise:
Promise<ExportListResponse>
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>
</>
)
}data
data:
ExportListResponse
The last successfully resolved data for the query.
error
error:
null
The error object for the query, if an error was thrown.
- Defaults to
null.
isError
isError:
false
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isPending
isPending:
false
Will be pending if there’s no cached data and no query attempt was finished yet.
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.
isRefetchError
isRefetchError:
false
Will be true if the query failed while refetching.
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.
isPlaceholderData
isPlaceholderData:
false
Will be true if the data shown is the placeholder data.
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.
latestExport
latestExport:
DataExport|undefined
{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: undefined; error: Error; isError: true; isPending: false; isLoading: false; isLoadingError: true; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "error"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
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.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
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.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
refetch()
refetch: (
options?) =>Promise<QueryObserverResult<ExportListResponse,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<ExportListResponse, Error>>
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.
promise
promise:
Promise<ExportListResponse>
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>
</>
)
}data
data:
undefined
The last successfully resolved data for the query.
error
error:
Error
The error object for the query, if an error was thrown.
- Defaults to
null.
isError
isError:
true
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isPending
isPending:
false
Will be pending if there’s no cached data and no query attempt was finished yet.
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.
isRefetchError
isRefetchError:
false
Will be true if the query failed while refetching.
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.
isPlaceholderData
isPlaceholderData:
false
Will be true if the data shown is the placeholder data.
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.
latestExport
latestExport:
DataExport|undefined
{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: undefined; error: null; isError: false; isPending: true; isLoading: true; isLoadingError: false; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "pending"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
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.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
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.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
refetch()
refetch: (
options?) =>Promise<QueryObserverResult<ExportListResponse,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<ExportListResponse, Error>>
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.
promise
promise:
Promise<ExportListResponse>
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>
</>
)
}data
data:
undefined
The last successfully resolved data for the query.
error
error:
null
The error object for the query, if an error was thrown.
- Defaults to
null.
isError
isError:
false
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isPending
isPending:
true
Will be pending if there’s no cached data and no query attempt was finished yet.
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.
isRefetchError
isRefetchError:
false
Will be true if the query failed while refetching.
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.
isPlaceholderData
isPlaceholderData:
false
Will be true if the data shown is the placeholder data.
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.
latestExport
latestExport:
DataExport|undefined
{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isLoading: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: undefined; error: null; isError: false; isPending: true; isLoadingError: false; isRefetchError: false; isSuccess: false; isPlaceholderData: false; status: "pending"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
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.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
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.
isLoading
isLoading:
boolean
Is true whenever the first fetch for a query is in-flight.
- Is the same as
isFetching && isPending.
isInitialLoading
isInitialLoading:
boolean
Deprecated
isInitialLoading is being deprecated in favor of isLoading
and will be removed in the next major version.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
refetch()
refetch: (
options?) =>Promise<QueryObserverResult<ExportListResponse,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<ExportListResponse, Error>>
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.
promise
promise:
Promise<ExportListResponse>
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>
</>
)
}data
data:
undefined
The last successfully resolved data for the query.
error
error:
null
The error object for the query, if an error was thrown.
- Defaults to
null.
isError
isError:
false
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
isPending
isPending:
true
Will be pending if there’s no cached data and no query attempt was finished yet.
isLoadingError
isLoadingError:
false
Will be true if the query failed while fetching for the first time.
isRefetchError
isRefetchError:
false
Will be true if the query failed while refetching.
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.
isPlaceholderData
isPlaceholderData:
false
Will be true if the data shown is the placeholder data.
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.
latestExport
latestExport:
DataExport|undefined
{ dataUpdatedAt: number; errorUpdatedAt: number; failureCount: number; failureReason: Error \| null; errorUpdateCount: number; isFetched: boolean; isFetchedAfterMount: boolean; isFetching: boolean; isInitialLoading: boolean; isPaused: boolean; isRefetching: boolean; isStale: boolean; isEnabled: boolean; refetch: (options?) => Promise\<QueryObserverResult\<[ExportListResponse](../types/data-export-api.md#exportlistresponse), Error\>\>; fetchStatus: FetchStatus; promise: Promise\<[ExportListResponse](../types/data-export-api.md#exportlistresponse)\>; data: [ExportListResponse](../types/data-export-api.md#exportlistresponse); isError: false; error: null; isPending: false; isLoading: false; isLoadingError: false; isRefetchError: false; isSuccess: true; isPlaceholderData: true; status: "success"; latestExport: [DataExport](../types/data-export-api.md#dataexport) \| undefined; }
dataUpdatedAt
dataUpdatedAt:
number
The timestamp for when the query most recently returned the status as "success".
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.
errorUpdateCount
errorUpdateCount:
number
The sum of all errors.
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.
isPaused
isPaused:
boolean
A derived boolean from the fetchStatus variable, provided for convenience.
- The query wanted to fetch, but has been
paused.
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.
isEnabled
isEnabled:
boolean
true if this observer is enabled, false otherwise.
refetch()
refetch: (
options?) =>Promise<QueryObserverResult<ExportListResponse,Error>>
A function to manually refetch the query.
Parameters
options?
RefetchOptions
Returns
Promise<QueryObserverResult<ExportListResponse, Error>>
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.
promise
promise:
Promise<ExportListResponse>
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>
</>
)
}data
data:
ExportListResponse
The last successfully resolved data for the query.
isError
isError:
false
A derived boolean from the status variable, provided for convenience.
trueif the query attempt resulted in an error.
error
error:
null
The error object for the query, if an error was thrown.
- Defaults to
null.
isPending
isPending:
false
Will be pending if there’s no cached data and no query attempt was finished yet.
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.
isRefetchError
isRefetchError:
false
Will be true if the query failed while refetching.
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.
isPlaceholderData
isPlaceholderData:
true
Will be true if the data shown is the placeholder data.
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.
latestExport
latestExport:
DataExport|undefined
useRequestDataExportMutation()
useRequestDataExportMutation():
UseMutationResult<RequestExportResponse,Error,void,unknown>
Hook to request a new data export.
Returns
UseMutationResult<RequestExportResponse, Error, void, unknown>
References
DataExport
Re-exports DataExport
ExportListResponse
Re-exports ExportListResponse
RequestExportError
Re-exports RequestExportError
RequestExportResponse
Re-exports RequestExportResponse
formatExportDate
Re-exports formatExportDate
getExportDownloadUrl
Re-exports getExportDownloadUrl
getTimeUntilExpiry
Re-exports getTimeUntilExpiry
formatFileSize
Re-exports formatFileSize