-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
404b92d
commit d06f1db
Showing
10 changed files
with
257 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# useEventListener | ||
|
||
Listen for an event and automatically clean up the effect on un-mount | ||
|
||
## Example | ||
|
||
```tsx | ||
import * as React from "react"; | ||
import { useEventListener } from "@casper124578/useful/hooks/useEventListener"; | ||
|
||
const Component = () => { | ||
const buttonRef = React.useRef<HTMLButtonElement>(null); | ||
|
||
const myWindowHandler = (event) => { | ||
console.log(event); | ||
}; | ||
|
||
// listen anywhere on the `window` | ||
useEventListener({ eventName: "click", handler: myWindowHandler }); | ||
|
||
const myButtonHandler = (event) => { | ||
console.log("Button handler", event); | ||
}; | ||
|
||
// listen on the `button` | ||
useEventListener({ elementRef: buttonRef, eventName: "click", handler: myButtonHandler }); | ||
|
||
return ( | ||
<div> | ||
<p>Hello world!</p> | ||
|
||
<button ref={buttonRef}>Click me!</button> | ||
</div> | ||
); | ||
}; | ||
``` |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.