yuvrajkarna2717/react-hook-granth

[Feature]: Add useEventListener hook

開放

#2 建立於 2025年12月6日

 (0 則留言) (0 個反應) (0 位負責人)JavaScript (1 個分叉)auto 404
enhancementgood first issuehelp wanted

倉庫指標

星標
 (3 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南