import { useCallback, useState } from 'react';
/**
 * @see [React docs for suggested pattern](https://react.dev/learn/manipulating-the-dom-with-refs#how-to-manage-a-list-of-refs-using-a-ref-callback)
 * @returns A tuple containing a map of refs and a function to get a ref callback for a given id.
 */
const useRefMap = () => {
    const [map] = useState(() => new Map());
    const [cbMap] = useState(() => new Map());
    const getCallbackRef = useCallback((id) => {
        if (cbMap.has(id)) {
            return cbMap.get(id);
        }
        const cb = el => {
            if (el !== null) {
                map.set(id, el);
            }
            else {
                map.delete(id);
            }
        };
        cbMap.set(id, cb);
        return cb;
    }, []);
    return [map, getCallbackRef];
};
export default useRefMap;
//# sourceMappingURL=useRefMap.js.map