Skip to content

Add useEventListener, useWindowEvent, and useDocumentEvent hooks#27

Merged
sindresorhus merged 3 commits intomainfrom
use-event
Feb 5, 2026
Merged

Add useEventListener, useWindowEvent, and useDocumentEvent hooks#27
sindresorhus merged 3 commits intomainfrom
use-event

Conversation

@sindresorhus
Copy link
Copy Markdown
Owner

Fixes #26


I realize it looks complicated, but this is the simplest I could do while still handling everything details around React correctly. It does a lot so the user doesn't have to use useMemo for options and stuff.

@sindresorhus sindresorhus mentioned this pull request Feb 3, 2026
Copy link
Copy Markdown
Contributor

@Richienb Richienb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test when wrapping callback with useEffectEvent

Copy link
Copy Markdown
Contributor

@Richienb Richienb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the options value required to be an object?
Before normalizing, we'd need to check the options type.
But, after normalizing, we're still doing a check to options.type, so normalization might not be needed.

@sindresorhus
Copy link
Copy Markdown
Owner Author

Options can be boolean or object. I now type‑check, treat null/non‑objects as “no options” and keep normalization for stable equality. Added tests for boolean and null options.

@sindresorhus sindresorhus merged commit 95cc33d into main Feb 5, 2026
4 checks passed
@sindresorhus sindresorhus deleted the use-event branch February 5, 2026 04:53
Copy link
Copy Markdown

@jjrauch32-lab jjrauch32-lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k

Repository owner deleted a comment from Clarence212 Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useEvent

3 participants