import * as React from "react";
import { Window } from "../utils/globals.js";
function useEventListener(type, eventHandler, element = Window, options = { passive: true }, enabled = true) {
  React.useEffect(() => {
    if (element && enabled) {
      element.addEventListener(type, eventHandler, options);
      return () => {
        if (typeof options === "object") {
          const { once, passive, ...removeOptions } = options;
          element.removeEventListener(type, eventHandler, removeOptions);
        } else {
          element.removeEventListener(type, eventHandler, options);
        }
      };
    }
    return void 0;
  }, [eventHandler, element, type, enabled, options]);
}
export {
  useEventListener
};
//# sourceMappingURL=useEventListener.js.map
