SSE Hooks

useEventListener

GitHub
Custom hook that attaches event listeners to DOM elements, the window, or media query lists.

Installation

npx 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-

boolean | AddEventListenerOptions

eventName-

K

handler-

(event: any) => void

element-

RefObject<MediaQueryList>

Returns

Return Value Default Type
return-

void

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

Built with Love • © 2026