UseAsyncDataResT
import { type UseAsyncDataResT } from '@dr.pogodin/react-global-state';
UseAsyncDataResT is the type of result returned by useAsyncData() and useAsyncCollection() hooks.
It is defined as the generic type:
type UseAsyncDataResT<DataT> = {
data: DataT | null;
loading: boolean;
reload: (loader?: AsyncDataLoaderT<DataT>) => Promise<void>;
timestamp: number;
};
Generic Parameters
DataT
— The type of datum managed by useAsyncData() or useAsyncCollection() hook.
Fields
-
data
— DataT | null — The datum, if loaded; null otherwise. -
loading
— boolean — true if the loading operation is currently underway; false otherwise. -
reload
— (loader?: AsyncDataLoaderT<DataT>) => Promise<void> — Imperatively triggers a reload of data at the corresponding path in the global state, using provided customloader
, if any, or otherwise the loader given to the corresponding useAsyncData() hook.tipThis method is intended for use in the imperative code (like mouse event handlers). When data should be reloaded in a response to the local or global state change, prefer to use
deps
option of UseAsyncDataOptionsT. -
timestamp
— number — The timestamp (milliseconds) whendata
, if any, were loaded (or the last time refreshed).cautionIf
data
is null because async data loaded into the state do not satisfy the maxage limit, the value oftimestamp
still will correspond to the time when those async data were loaded into the state.