import { useEffect, useRef } from 'react';
export var useGlobalKeys = function (keyHandlers, eventType) {
    if (eventType === void 0) { eventType = 'keyup'; }
    var keyHandlersRef = useRef({});
    useEffect(function () {
        keyHandlersRef.current = keyHandlers;
    }, [keyHandlers]);
    useEffect(function () {
        var handler = function (e) {
            var current = keyHandlersRef.current;
            var userHandler = current[e.code] || current[e.key];
            userHandler && userHandler(e);
        };
        document.addEventListener(eventType, handler);
        return function () {
            document.removeEventListener(eventType, handler);
        };
    }, [eventType]);
};
