• Attaches an event listener directly to the provided DOM element.

    Bypassing React's event system can be desirable, for instance when attaching non-passive event handlers.

    const ref = useRef(null)

    useDomEvent(ref, 'wheel', onWheel, { passive: false })

    return <div ref={ref} />

    Parameters

    • ref: RefObject<EventTarget>

      React.RefObject that's been provided to the element you want to bind the listener to.

    • eventName: string

      Name of the event you want listen for.

    • Optional handler: EventListener

      Function to fire when receiving the event.

    • Optional options: AddEventListenerOptions

      Options to pass to Event.addEventListener.

    Returns void

Generated using TypeDoc