Skip to content

Commit

Permalink
Fix useEventListener not accepting global event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Apr 20, 2023
1 parent 75c705e commit 16e3273
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/useEventListener.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useEffect } from 'react';

type GlobalAndWindowEventHandlersEventMap = WindowEventHandlersEventMap &
GlobalEventHandlersEventMap;

/**
* Adds event listener to a given element.
*
Expand All @@ -13,10 +16,10 @@ export default function useEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
): void;
export default function useEventListener<U extends keyof WindowEventHandlersEventMap>(
export default function useEventListener<U extends keyof GlobalAndWindowEventHandlersEventMap>(
element: Window | null,
type: U,
listener: (event: WindowEventHandlersEventMap[U]) => void,
listener: (event: GlobalAndWindowEventHandlersEventMap[U]) => void,
): void;
export default function useEventListener<U extends keyof DocumentEventMap>(
element: Document | null,
Expand Down

0 comments on commit 16e3273

Please sign in to comment.