yuvrajkarna2717/react-hook-granth

[Feature]: Add useEventListener hook

Offen

#2 geöffnet am 06.12.2025

 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (1 Fork)auto 404
enhancementgood first issuehelp wanted

Repository-Metriken

Stars
 (3 Sterne)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

Hook Name

useEventListener

Feature Description

Description: Create a useEventListener hook that provides a clean way to attach and detach event listeners in React components.

Requirements:

  • Should work with DOM elements, window, and document
  • Automatically clean up listeners on unmount
  • TypeScript support with proper event typing
  • SSR safe

Acceptance Criteria:

  • Hook implementation in src/hooks/useEventListener.ts
  • Export from src/index.ts
  • Unit tests in src/__tests__/useEventListener.test.js
  • TypeScript definitions

Use Case

It provides a clean way to attach and detach event listeners in React components.

Proposed API

API Proposal:

useEventListener('click', handleClick, elementRef);
useEventListener('resize', handleResize); // defaults to window

Contributor Guide