import { useState } from 'react'; export interface Actions { get: (key: K) => any; set: (key: K, value: V) => void; remove: (key: K) => void; reset: () => void; } const useMap = (initialMap: any = {}): [T, Actions] => { const [map, set] = useState(initialMap as any); return [ map, { get: (key: string) => map[key], set: (key: string, entry: any) => set({ ...(map as any), [key]: entry, }), remove: (key: string) => { const { [key]: omit, ...rest } = map as any; set(rest); }, reset: () => set(initialMap), }, ]; }; export default useMap;