Skip to content

Commit c0b6ed5

Browse files
Merge pull request #34 from reaviz/keys-fn-issue
Use import type for types [possible fix for #33]
2 parents 4dacf19 + 34f383d commit c0b6ed5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/useHotkeys.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RefObject, useEffect, useLayoutEffect, useState } from 'react';
2-
import keys, { Callback, Handler, Key } from 'ctrl-keys';
2+
import type { Callback, HandlerInterface, Key } from 'ctrl-keys';
3+
import keys from 'ctrl-keys';
34

45
type Keys = [Key] | [Key, Key] | [Key, Key, Key] | [Key, Key, Key, Key];
56

@@ -24,7 +25,7 @@ const keydownGlobalHandler = keys();
2425
/**
2526
* Map of specific elements handlers
2627
*/
27-
const handlers = new Map<HTMLElement, Handler>();
28+
const handlers = new Map<HTMLElement, HandlerInterface>();
2829
let hotkeys: HotkeyShortcuts[] = [];
2930

3031
const extractKeys = (keys: string | string[]): Keys => {
@@ -78,10 +79,9 @@ const registerElementShortcut = (shortcut: HotkeyShortcuts) => {
7879

7980
const removeElementShortcut = (shortcut: HotkeyShortcuts) => {
8081
if (shortcut.ref?.current && !shortcut.disabled) {
81-
const handler = handlers.get(shortcut.ref?.current) as Handler;
82-
83-
handler.remove(...extractKeys(shortcut.keys), shortcut.callback);
82+
const handler = handlers.get(shortcut.ref?.current) as HandlerInterface;
8483

84+
handler?.remove(...extractKeys(shortcut.keys), shortcut.callback);
8585
shortcut.ref?.current?.removeEventListener(shortcut.action ?? 'keypress', handler.handle);
8686
}
8787
};

0 commit comments

Comments
 (0)