DOM & Events
useEventListener
Add and cleanup event listeners with automatic memory management.
import { useEventListener } from "saha-ui"Uses
Attach and clean up event listeners on window, element refs, or arbitrary elements with correct handler updates.
Props
| Name | Type | Description | Default |
|---|---|---|---|
| eventName | string | Event string (typed to `WindowEventMap` where possible). | - |
| handler | function | Callback invoked with event. | - |
| element | Ref | Element | window | Optional target. Default: window. | - |
| options | object | boolean | AddEventListenerOptions or boolean. | - |
Returns
| Name | Description |
|---|---|
| void | No return; installs listener and cleans on unmount. |
Example
useEventListener('keydown', (e) => console.log(e.key));
useEventListener('click', handleClick, buttonRef);Notes
Handler is stored in a ref so the effect doesn't re-subscribe on every render.