const useMap = (state?: Iterable) => { const [map, setMap] = useState>(new Map(state ?? []));

    const set = useCallback( (key: K, value: V) => { setMap((prev) => { const t = new Map(prev); t.set(key, value); return t; }); }, [setMap], );

    const has = useCallback((key: K) => map.has(key), [map]);

    const get = useCallback((key: K) => map.get(key), [map]);

    const remove = useCallback( (key: K) => { setMap((prev) => { const t = new Map(prev); t.delete(key); return t; }); }, [map], );

    const toArray = useCallback(() => { return Array.from(map); }, [map]);

    const toObject = useCallback(() => { return Object.fromEntries(map); }, [map]);

    return [map, { set, has, get, remove, toArray, toObject }] as const; };

    export default useMap;

    ```