feat: DH-21211: Adding window listener hook#2620
feat: DH-21211: Adding window listener hook#2620jnumainville merged 4 commits intodeephaven:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a reusable React hook useWindowListener for managing window event listeners with automatic cleanup. The hook simplifies the common pattern of adding and removing event listeners in React components by handling the lifecycle management automatically.
Changes:
- New
useWindowListenerhook that accepts single or multiple event types, a callback function, and optional listener options - Comprehensive test suite covering event registration/cleanup, dependency updates, and edge cases
- Hook implementation uses
useMemofor event array normalization anduseEffectfor listener lifecycle management
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/react-hooks/src/useWindowListener.ts | Implements the hook with support for single/multiple events, callback handling, and options forwarding |
| packages/react-hooks/src/useWindowListener.test.ts | Provides extensive test coverage for various scenarios including unmounting, dependency changes, and event dispatching |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2620 +/- ##
==========================================
- Coverage 49.76% 49.52% -0.25%
==========================================
Files 773 774 +1
Lines 43759 43767 +8
Branches 11072 11256 +184
==========================================
- Hits 21777 21674 -103
- Misses 21964 22047 +83
- Partials 18 46 +28
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Adding window listener hook as mentioned in https://github.com/deephaven-ent/iris/pull/3926