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

贡献者指南