AsyncCollectionLoaderT
import { type AsyncCollectionLoaderT } from '@dr.pogodin/react-global-state';
The AsyncCollectionLoaderT type is the signature of a valid data loader function for the useAsyncCollection() hook.
It is defined as a generic type:
type AsyncCollectionLoaderT<DataT> =
(id: string, oldData: null | DataT) => DataT | Promise<DataT>
Generic Parameters
Arguments
The data loader function receives two arguments:
id
— string — The identifier of collection item to load.oldData
— DataT | null — The item previously loaded for thisid
, if any; or null.
Result
The data loader function should return either a Promise of DataT value for the given ID, 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.