UseAsyncDataResT
import { type UseAsyncDataResT } from '@dr.pogodin/react-global-state';
UseAsyncDataResT is the type of result returned by useAsyncData() and, possibly (depends on hook's arguments), useAsyncCollection() hooks.
It is defined as the generic type:
type UseAsyncDataResT<DataT> = {
data: DataT | null;
loading: boolean;
reload: AsyncDataReloaderT<DataT>;
set: (data: DataT | null) => 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— AsyncDataReloaderT — 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.Tips-
This method is intended for imperative code (e.g. UI event handlers). When data should be reloaded in response to local or global state changes, prefer to use
depsoption of UseAsyncDataOptionsT to manage reloads. -
This method is a stable function — it is guaranteed to remain the same across re-renders of the host component.
-
-
set— (data: DataT | null) => void — Synchronously writes givendatainto the envelope at the corresponding path of the global state. -
timestamp— number — The timestamp (milliseconds) whendata, if any, were loaded (or the last time refreshed).cautionIf
datais null because async data loaded into the state do not satisfy the maxage limit, the value oftimestampstill will correspond to the time when those async data were loaded into the state.