const { data, error, isLoading, isFetching, accessor } = useAccessor(accessor, getSnapshot, {
retryCount: 3,
retryInterval: 1000,
revalidateOnMount: false,
revalidateIfStale: false,
revalidateOnFocus: false,
revalidateOnReconnect: false,
dedupeInterval: 2000,
pollingInterval: 0,
checkHasData: value => !isUndefined(value),
keepPreviousData: false,
placeholderData: undefined,
pollingWhenHidden: false,
staleTime: 0,
});
The data returned from the getSnapshot
function.
If the accessor fails to fetch the data after retrying, this property will hold the thrown error. It will be set to null
if the fetch is successful.
Indicates whether the accessor is currently fetching data.
This will be true
if checkHasData
returns false
and the accessor is fetching. Otherwise, it will be false
.
The accessor provided as the first parameter.
The accessor to automatically call its revalidate
method and subscribe to its model. It can be null
. For more information, refer to conditional fetching.
A function that returns the data you want from the model's state. This parameter is required because the data structure can vary. However, this parameter can be omitted if you use this hook with auto model.
The number of retry attempts for errors.
The time span in milliseconds for deduplicating requests with the same accessor.
Whether to revalidate when the accessor
changes.
Whether to revalidate when the accessor becomes stale.
Whether the accessor should revalidate data when the user refocuses the page.
Whether the accessor should revalidate data when the user reconnects to the network.
The time span in milliseconds for deduplicating requests with the same accessor.
The interval in milliseconds for polling data. If the value is less than or equal to 0, polling is disabled.
A function that determines whether the returned data from getSnapshot
is valid. If it's not, revalidation will occur.
Keep the previous data until new data is fetched.
This value will be used as placeholder data if isLoading
is true
.
pollingWhenHidden
If true
and pollingInterval
is greater than zero, continue to refetch data even when the user's tab is hidden.
The time in milliseconds after which data is considered stale.