UNPKG

@ducor/react

Version:

admin template ui interface

18 lines (17 loc) 603 B
import { useEffect } from "react"; import { useCallbackRef } from "./use-outside-click"; /** * `useWindowEvent` is a custom hook that assigns an event listener to `window`. * * @see Docs https://ui.ducor.net/hooks/use-window-event */ var useWindowEvent = function (event, handler, options) { var listener = useCallbackRef(handler); useEffect(function () { window.addEventListener(event, listener, options); return function () { window.removeEventListener(event, listener, options); }; }, [event, listener, options]); }; export default useWindowEvent;