Skip to content

useEventListener не работает с дом элементом как первый аргумент #454

@geril07

Description

@geril07

* @overload
* @template Event Key of window event map
* @param {Window} target The window object to attach the event listener to
* @param {Event | Event[]} event An array of event types to listen for
* @param {(this: Window, event: WindowEventMap[Event]) => void} handler The event handler function
* @param {UseEventListenerOptions} [options] Options for the event listener
* @returns {void}
*
* @example
* useEventListener(window, 'click', () => console.log('click'));
*
* @overload
* @template Event Key of window event map
* @param {Document} target The window object to attach the event listener to
* @param {Event | Event[]} event An array of event types to listen for
* @param {(this: Document, event: DocumentEventMap[Event]) => void} handler The event handler function
* @param {UseEventListenerOptions} [options] Options for the event listener
* @returns {void}
*
* @example
* useEventListener(document, 'click', () => console.log('click'));

по доке указано, что можно передавать элемент как первый аргумент, но ts ругается и это не работает

https://codesandbox.io/p/sandbox/yshdc3?file=%2Fsrc%2FApp.tsx%3A14%2C1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions