yuvrajkarna2717/react-hook-granth

[Feature]: Add useEventListener hook

オープン

#2 opened on 2025/12/06

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (1 件のフォーク)auto 404
enhancementgood first issuehelp wanted

Repository metrics

Stars
 (3 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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

コントリビューターガイド