Skip to main content

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

  • DataT — The type of data loaded by the loader function.

Arguments

The data loader function receives two arguments:

  • idstring — The identifier of collection item to load.
  • oldDataDataT | null — The item previously loaded for this id, if any; or null.

Result

The data loader function must either return a Promise resolving to a DataT value for the given ID, or just return the DataT value directly.