@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
32 lines (28 loc) • 794 B
JavaScript
"use client";
import { useCallbackRef } from "../../utils/ref.js";
import { useEnvironment } from "../../core/system/environment-provider.js";
import { useEffect } from "react";
//#region src/hooks/use-window-event/index.ts
/**
* `useWindowEvent` is a custom hook that assigns an event listener to `window`.
*
* @see https://yamada-ui.com/docs/hooks/use-window-event
*/
const useWindowEvent = (ev, handler, options) => {
const { getWindow } = useEnvironment();
const listener = useCallbackRef(handler);
useEffect(() => {
getWindow()?.addEventListener(ev, listener, options);
return () => {
getWindow()?.removeEventListener(ev, listener, options);
};
}, [
ev,
listener,
options,
getWindow
]);
};
//#endregion
export { useWindowEvent };
//# sourceMappingURL=index.js.map