Skip to content

Commit

Permalink
docs: update useEventListener doc
Browse files Browse the repository at this point in the history
  • Loading branch information
juliencrn committed Dec 21, 2022
1 parent 5611309 commit 4c1ad0c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/useEventListener/useEventListener.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@ date: '2020-06-28'
Use EventListener with simplicity by React Hook.

Supports `Window`, `Element` and `Document` and custom events with almost the same parameters as the native [`addEventListener` options](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#syntax). See examples below.

If you want to use your CustomEvent using Typescript, you have to declare the event type.
Find witch kind of Event you want to extends:

- `MediaQueryListEventMap`
- `WindowEventMap`
- `HTMLElementEventMap`
- `DocumentEventMap`

Then declare your custom event:

```ts
declare global {
interface DocumentEventMap {
'my-custom-event': CustomEvent<{ exampleArg: string }>
}
}
```

0 comments on commit 4c1ad0c

Please sign in to comment.