↩ Strongly typed, concurrent mode-safe React hooks
Installations
npm install @react-hook/event
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Score
98.1
Supply Chain
97.2
Quality
75.8
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Languages
TypeScript (85.29%)
JavaScript (14.55%)
Shell (0.17%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
26,351,531
Last Day
39,041
Last Week
39,041
Last Month
565,097
Last Year
9,089,629
GitHub Statistics
1,467 Stars
429 Commits
97 Forks
10 Watching
14 Branches
27 Contributors
Bundle Size
545.00 B
Minified
326.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.2.6
Package Id
@react-hook/event@1.2.6
Size
7.07 kB
Publised On
27 Oct 2021
Total Downloads
Cumulative downloads
Total Downloads
26,351,531
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
useEvent()
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.
Quick Start
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}
API
useEvent(target, type, listener)
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. |
LICENSE
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 17 are checked with a SAST tool
Reason
35 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-rxrc-rgv4-jpvx
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
2.7
/10
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 MoreOther packages similar to @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