AsyncDataLoaderT
import { type AsyncDataLoaderT } from '@dr.pogodin/react-global-state';
The AsyncDataLoaderT type is the signature of a valid data loader function for the useAsyncData() hook.
It is defined as a generic type:
export type AsyncDataLoaderT<DataT>
= (oldData: null | DataT) => DataT | Promise<DataT>;
Generic Parameters
Arguments
oldData
— DataT | null — The previously loaded item, if any; or null.
Result
The data loader function should return either a Promise of DataT value, or DataT value directly. In the former case, the corresponding envelope in the global state will be in the (re-)loading state while the promise resolution or rejection is awaited; in the later case DataT value will be writted into the envelope synchronously, without visiting the intermediate (re-)loading state.