Content
useEventListener
A custom hook to add and clean up an event listener on any target element.
useEventListener
Usage
API
useEventListener
Adds an event listener to the target element.
Parameters
Name | Type | Description |
---|---|---|
eventName | K | The event type (e.g. 'click', 'scroll', 'resize', etc.). |
handler | (event: WindowEventMap[K]) => void | The event handler function. |
element | RefObject<HTMLElement> | Window | The target element to attach the event listener to. Default is window . |
Returns
Name | Type | Description |
---|---|---|
undefined | void |