@supunlakmal/hooks
Version:
A collection of reusable React hooks
20 lines (19 loc) • 754 B
TypeScript
interface MapActions<K, V> {
set: (key: K, value: V) => void;
setAll: (entries: Iterable<readonly [K, V]>) => void;
remove: (key: K) => void;
reset: () => void;
clear: () => void;
get: (key: K) => V | undefined;
}
type UseMapResult<K, V> = [Map<K, V>, MapActions<K, V>];
/**
* Custom hook to manage state as a Map, providing helper functions.
*
* @template K - The type of the keys in the Map.
* @template V - The type of the values in the Map.
* @param initialMap - Optional initial Map or an iterable of key-value pairs.
* @returns A tuple containing the current Map state and an actions object.
*/
export declare const useMap: <K, V>(initialMap?: Map<K, V> | Iterable<readonly [K, V]>) => UseMapResult<K, V>;
export {};