Gathering detailed insights and metrics for @react-hook/event
Gathering detailed insights and metrics for @react-hook/event
Gathering detailed insights and metrics for @react-hook/event
Gathering detailed insights and metrics for @react-hook/event
@chakra-ui/react-use-pan-event
React hook to track pan events
react-swipeable
React Swipe event handler hook
react-use-event-hook
Same as React's `useCallback`, but returns a stable reference.
use-latest-callback
React hook which returns the latest callback without changing the reference
npm install @react-hook/event
Typescript
Module System
TypeScript (85.29%)
JavaScript (14.55%)
Shell (0.17%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,514 Stars
429 Commits
96 Forks
9 Watchers
14 Branches
27 Contributors
Updated on Jul 09, 2025
Latest Version
1.2.6
Package Id
@react-hook/event@1.2.6
Size
7.07 kB
Published on
Oct 27, 2021
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
npm i @react-hook/event
A React hook for adding events to HTML elements. This hook cleans up your listeners
automatically when it unmounts. You won't have to worry about wrapping your
listener in a useCallback()
because this hook makes sure your most recent callback
is always invoked.
1import * as React from 'react' 2import useEvent from '@react-hook/event' 3 4// Logs an event each time target.current is clicked 5const Component = () => { 6 const target = useRef(null) 7 useEvent(target, 'click', (event) => console.log(event)) 8 return <div ref={target} /> 9} 10 11// Logs an event each time the `document` is clicked 12const useLogDocumentClick = () => { 13 useEvent(document, 'click', (event) => console.log(event)) 14} 15 16// Logs an event each time the `window` is clicked 17const useLogWindowClick = () => { 18 useEvent(window, 'click', (event) => console.log(event)) 19} 20 21// Logs an event each time element#foo` is clicked 22const useLogElementClick = () => { 23 useEvent(document.getElementById('foo'), 'click', (event) => 24 console.log(event) 25 ) 26}
1const useEvent = < 2 // Also has Window, Document overloads 3 T extends HTMLElement = HTMLElement, 4 K extends keyof HTMLElementEventMap = keyof HTMLElementEventMap 5>( 6 target: React.RefObject<T> | T | Window | Document | null, 7 type: K, 8 listener: EventListener<K>, 9 cleanup?: (...args: any[]) => any 10)
Argument | Type | Required? | Description |
---|---|---|---|
target | React.RefObject<T> | T | Window | Document | null | Yes | The React ref, window , or document to add the event listener to |
type | keyof EventMap | Yes | The type of event to listen for |
listener | (this: T, ev: EventMap[K]) => any | Yes | The callback invoked when the event type fires |
cleanup | (...args: any[]) => any | No | This callback will be invoked when the event unmounts. This is in addition to the automatic event listener cleanup that occurs. A common use case could be something like clearing a timeout. |
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 14/28 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
37 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More