import * as React from 'react'; /** * The options for the `useEventListener` hook. */ export interface UseEventListenerOptions { /** * The target element to bind the event listener to. * @default 'document' */ target?: 'document' | 'window' | 'body' | HTMLElement | (() => HTMLElement) | React.Ref | string | null; /** * The event type to listen for. */ type: T | string; /** * The event listener callback. */ listener: EventListener; /** * The event listener options */ options?: AddEventListenerOptions | boolean; /** * A boolean indicating whether the event listener should be active. */ when?: boolean; } /** * The return type of the `useEventListener` hook. * A tuple containing functions; * 1. `bind` function is used to bind the event listener. * 2. `unbind` function is used to unbind the event listener. */ export type UseEventListenerReturnType = [(options?: Partial> & { target?: UseEventListenerOptions['target'] | Document | null; }) => void, () => void]; /** * Listens for the specified event type on the target element. * * @param {UseEventListenerOptions} options - The options for the event listener. * @returns A tuple containing functions; * 1. `bind` function is used to bind the event listener. * 2. `unbind` function is used to unbind the event listener. * * @example * ```tsx * const Component = () => { * const [bind, unbind] = useEventListener({ * target: 'document', * type: 'click', * listener: (event) => { * console.log(event); * }, * when: true * }); * * return
Click me
; * }; * * @example * ```tsx * const Component = () => { * const [bind, unbind] = useEventListener({ * target: () => document.querySelector('.element'), * type: 'mouseover', * listener: (event) => { * console.log(event); * } * }); * * return
MouseOver to `.element`
; * }; * ``` */ export declare function useEventListener({ target, type, listener, options, when }: UseEventListenerOptions): UseEventListenerReturnType;