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
↩ Strongly typed, concurrent mode-safe React hooks
npm install @react-hook/event
Typescript
Module System
98.1
Supply Chain
97.2
Quality
75.8
Maintenance
100
Vulnerability
100
License
TypeScript (85.29%)
JavaScript (14.55%)
Shell (0.17%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
26,351,531
Last Day
39,041
Last Week
39,041
Last Month
565,097
Last Year
9,089,629
1,467 Stars
429 Commits
97 Forks
10 Watching
14 Branches
27 Contributors
Minified
Minified + Gzipped
Latest Version
1.2.6
Package Id
@react-hook/event@1.2.6
Size
7.07 kB
Publised On
27 Oct 2021
Cumulative downloads
Total Downloads
Last day
0%
39,041
Compared to previous day
Last week
-65.4%
39,041
Compared to previous week
Last month
-5.1%
565,097
Compared to previous month
Last year
19.1%
9,089,629
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
2 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
35 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-03
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@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