react-hotkeys-hook
Advanced tools
Comparing version 1.5.4 to 1.6.0
@@ -10,8 +10,9 @@ 'use strict'; | ||
function useHotkeys(keys, callback, deps = []) { | ||
function useHotkeys(keys, callback, deps = [], options = {}) { | ||
const memoisedCallback = react.useCallback(callback, deps); | ||
react.useEffect(() => { | ||
if (options.filter) hotkeys.filter = options.filter; | ||
hotkeys(keys, memoisedCallback); | ||
return () => hotkeys.unbind(keys, memoisedCallback); | ||
}, [memoisedCallback]); | ||
}, [memoisedCallback, options]); | ||
} | ||
@@ -18,0 +19,0 @@ |
@@ -1,9 +0,11 @@ | ||
import hotkeys from 'hotkeys-js'; | ||
import hotkeys from "hotkeys-js"; | ||
import { useCallback, useEffect } from "react"; | ||
export function useHotkeys(keys, callback, deps = []) { | ||
export function useHotkeys(keys, callback, deps = [], options = {}) { | ||
const memoisedCallback = useCallback(callback, deps); | ||
useEffect(() => { | ||
if (options.filter) | ||
hotkeys.filter = options.filter; | ||
hotkeys(keys, memoisedCallback); | ||
return () => hotkeys.unbind(keys, memoisedCallback); | ||
}, [memoisedCallback]); | ||
}, [memoisedCallback, options]); | ||
} |
@@ -1,4 +0,7 @@ | ||
import { HotkeysEvent } from 'hotkeys-js'; | ||
import hotkeys, { HotkeysEvent } from "hotkeys-js"; | ||
declare type CallbackFn = (event: KeyboardEvent, handler: HotkeysEvent) => void; | ||
export declare function useHotkeys(keys: string, callback: CallbackFn, deps?: any[]): void; | ||
declare type Options = { | ||
filter?: typeof hotkeys.filter; | ||
}; | ||
export declare function useHotkeys(keys: string, callback: CallbackFn, deps?: any[], options?: Options): void; | ||
export {}; |
import hotkeys from 'hotkeys-js'; | ||
import { useCallback, useEffect } from 'react'; | ||
function useHotkeys(keys, callback, deps = []) { | ||
function useHotkeys(keys, callback, deps = [], options = {}) { | ||
const memoisedCallback = useCallback(callback, deps); | ||
useEffect(() => { | ||
if (options.filter) | ||
hotkeys.filter = options.filter; | ||
hotkeys(keys, memoisedCallback); | ||
return () => hotkeys.unbind(keys, memoisedCallback); | ||
}, [memoisedCallback]); | ||
}, [memoisedCallback, options]); | ||
} | ||
@@ -11,0 +13,0 @@ |
{ | ||
"name": "react-hotkeys-hook", | ||
"version": "1.5.4", | ||
"version": "1.6.0", | ||
"license": "MIT", | ||
@@ -31,19 +31,19 @@ "files": [ | ||
"devDependencies": { | ||
"@babel/core": "7.7.5", | ||
"@babel/preset-env": "7.7.6", | ||
"@babel/preset-react": "7.7.4", | ||
"@babel/preset-typescript": "7.7.4", | ||
"@emotion/core": "10.0.22", | ||
"@babel/core": "7.8.7", | ||
"@babel/preset-env": "7.8.7", | ||
"@babel/preset-react": "7.8.3", | ||
"@babel/preset-typescript": "7.8.3", | ||
"@emotion/core": "10.0.28", | ||
"@pika/pack": "0.5.0", | ||
"@pika/plugin-build-node": "0.8.1", | ||
"@pika/plugin-build-types": "0.8.1", | ||
"@pika/plugin-build-web": "0.8.1", | ||
"@pika/plugin-ts-standard-pkg": "0.8.1", | ||
"@types/react": "16.9.15", | ||
"@types/react-dom": "16.9.4", | ||
"docz": "2.1.1", | ||
"emotion-theming": "10.0.19", | ||
"react": "16.12.0", | ||
"react-dom": "16.12.0", | ||
"typescript": "3.7.3" | ||
"@pika/plugin-build-node": "0.9.2", | ||
"@pika/plugin-build-types": "0.9.2", | ||
"@pika/plugin-build-web": "0.9.2", | ||
"@pika/plugin-ts-standard-pkg": "0.9.2", | ||
"@types/react": "16.9.23", | ||
"@types/react-dom": "16.9.5", | ||
"docz": "2.2.0", | ||
"emotion-theming": "10.0.27", | ||
"react": "16.13.0", | ||
"react-dom": "16.13.0", | ||
"typescript": "3.8.3" | ||
}, | ||
@@ -50,0 +50,0 @@ "source": "dist-src/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10965
46