UNPKG

rooks

Version:

Essential React custom hooks ⚓ to super charge your components!

19 lines (18 loc) 906 B
import { useGlobalObjectEventListener } from "./useGlobalObjectEventListener"; /** * useDocumentEventListener hook * * @description A react hook to an event listener to the document * * @param {string} eventName The event to track * @param {Function} callback The callback to be called on event * @param {ListenerOptions} listenerOptions The options to be passed to the event listener * @param {boolean} isLayoutEffect Should it use layout effect. Defaults to false * @see https://react-hooks.org/docs/useDocumentEventListener */ function useDocumentEventListener(eventName, callback, listenerOptions, isLayoutEffect) { if (listenerOptions === void 0) { listenerOptions = {}; } if (isLayoutEffect === void 0) { isLayoutEffect = false; } useGlobalObjectEventListener(global.document, eventName, callback, listenerOptions, true, isLayoutEffect); } export { useDocumentEventListener };