useEventListener
Custom hook that attaches event listeners to DOM elements, the window, or media query lists.
Installation
npx sse-hooks add use-event-listener
yarn dlx sse-hooks add use-event-listener
pnpm dlx sse-hooks add use-event-listener
deno run -A npm:sse-hooks add use-event-listener
bunx sse-hooks add use-event-listener
Usage
example.ts
import { useEventListener } from "./{hooks file}";
// Example 1: Attach a window event listener
useEventListener("resize", handleResize);
API
Parameters
| Prop | Default | Type |
|---|---|---|
options | - |
|
eventName | - |
|
handler | - |
|
element | - |
|
Returns
| Return Value | Default | Type |
|---|---|---|
return | - |
Hook return value |
Types Aliases
No specific type aliases defined for this component.
Changelog
81e9f — feat: update documentation and categorize hooks
c165d — feat: enhance useRoleGuard and useSSR hooks with additional options and documentation
30da4 — feat: add new hooks and their metadata
cf13e — feat: add custom hooks for step navigation, ternary dark mode, timeout, toggle, unmount, and window size