{() => {
const [amount, setAmount] = useState(0);
- useHotkeys('m', () => setAmount(amount => amount + 100));
+ useHotkeys('l', () => setAmount(amount => amount + 100));
return (
Add {amount} dollars to my bank account.
diff --git a/src/index.ts b/src/index.ts
index 38c60c70..ecd76654 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,5 +1,5 @@
import hotkeys, {KeyHandler} from "hotkeys-js";
-import {useCallback, useEffect} from "react";
+import {useCallback, useEffect, useMemo} from "react";
type AvailableTags = 'INPUT' | 'TEXTAREA' | 'SELECT';
@@ -21,16 +21,14 @@ export function useHotkeys(
const memoisedCallback = useCallback(callback, deps);
useEffect(() => {
- hotkeys.filter = ({target, srcElement}) => {
- if (options.enableOnTags) {
+ if (options.enableOnTags) {
+ hotkeys.filter = ({target, srcElement}) => {
// @ts-ignore
const targetTagName = (target && target.tagName) || (srcElement && srcElement.tagName);
- return Boolean(targetTagName && options.enableOnTags.includes(targetTagName as AvailableTags));
- }
-
- return false;
- };
+ return Boolean(targetTagName && options.enableOnTags && options.enableOnTags.includes(targetTagName as AvailableTags));
+ };
+ }
if (options.filter) hotkeys.filter = options.filter;
diff --git a/tsconfig.json b/tsconfig.json
index b711ba19..ece7b207 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,11 +1,11 @@
{
"compilerOptions": {
- "target": "es2015",
- "module": "esnext",
+ "target": "ES5",
+ "module": "ESNext",
"moduleResolution": "node",
"jsx": "react",
"strict": true,
"allowSyntheticDefaultImports": true
},
"include": ["src"]
-}
\ No newline at end of file
+}