react-hotkeys-hook
Advanced tools
Comparing version 1.4.0 to 1.5.0
## [1.4.0] - 03-Jun-2019 | ||
* Add callback to useEffect deps to allow update of hotkeys when callback changes | ||
* This also fixes the stale state bug | ||
* Bump hotkeys version to 3.6.11 | ||
@@ -5,0 +6,0 @@ ## [1.3.4] - 11-May-2019 |
@@ -10,9 +10,10 @@ 'use strict'; | ||
function useHotkeys(keys, callback) { | ||
function useHotkeys(keys, callback, deps = []) { | ||
const memoisedCallback = react.useCallback(callback, deps); | ||
react.useEffect(() => { | ||
hotkeys(keys, (event, handler) => callback(event, handler)); | ||
hotkeys(keys, memoisedCallback); | ||
return () => hotkeys.unbind(keys); | ||
}, [callback]); | ||
}, [memoisedCallback]); | ||
} | ||
exports.useHotkeys = useHotkeys; |
import hotkeys from 'hotkeys-js'; | ||
import { useEffect } from "react"; | ||
export function useHotkeys(keys, callback) { | ||
import { useCallback, useEffect } from "react"; | ||
export function useHotkeys(keys, callback, deps = []) { | ||
const memoisedCallback = useCallback(callback, deps); | ||
useEffect(() => { | ||
hotkeys(keys, (event, handler) => callback(event, handler)); | ||
hotkeys(keys, memoisedCallback); | ||
return () => hotkeys.unbind(keys); | ||
}, [callback]); | ||
}, [memoisedCallback]); | ||
} |
import { HotkeysEvent } from 'hotkeys-js'; | ||
export declare function useHotkeys(keys: string, callback: (event: KeyboardEvent, handler: HotkeysEvent) => void): void; | ||
declare type CallbackFn = (event: KeyboardEvent, handler: HotkeysEvent) => void; | ||
export declare function useHotkeys(keys: string, callback: CallbackFn, deps?: any[]): void; | ||
export {}; |
import hotkeys from 'hotkeys-js'; | ||
import { useEffect } from 'react'; | ||
import { useCallback, useEffect } from 'react'; | ||
function useHotkeys(keys, callback) { | ||
let deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
const memoisedCallback = useCallback(callback, deps); | ||
useEffect(() => { | ||
hotkeys(keys, (event, handler) => callback(event, handler)); | ||
hotkeys(keys, memoisedCallback); | ||
return () => hotkeys.unbind(keys); | ||
}, [callback]); | ||
}, [memoisedCallback]); | ||
} | ||
export { useHotkeys }; |
{ | ||
"name": "react-hotkeys-hook", | ||
"description": "React hook for using keyboard shortcuts in components. This is a hook version for the [hotkeys] package.", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"license": "MIT", | ||
@@ -10,6 +9,2 @@ "files": [ | ||
], | ||
"source": "dist-src/index.js", | ||
"types": "dist-types/index.d.ts", | ||
"main": "dist-node/index.js", | ||
"module": "dist-web/index.js", | ||
"pika": true, | ||
@@ -31,3 +26,3 @@ "sideEffects": false, | ||
"dependencies": { | ||
"hotkeys-js": "3.6.11" | ||
"hotkeys-js": "3.6.12" | ||
}, | ||
@@ -38,8 +33,8 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "7.4.5", | ||
"@babel/preset-env": "7.4.5", | ||
"@babel/core": "7.5.5", | ||
"@babel/preset-env": "7.5.5", | ||
"@babel/preset-react": "7.0.0", | ||
"@babel/preset-typescript": "7.3.3", | ||
"@emotion/core": "10.0.10", | ||
"@pika/pack": "0.3.7", | ||
"@emotion/core": "10.0.14", | ||
"@pika/pack": "0.4.0", | ||
"@pika/plugin-build-node": "0.4.0", | ||
@@ -49,11 +44,15 @@ "@pika/plugin-build-types": "0.4.0", | ||
"@pika/plugin-ts-standard-pkg": "0.4.0", | ||
"@types/react": "16.8.19", | ||
"@types/react": "16.8.23", | ||
"@types/react-dom": "16.8.4", | ||
"docz": "1.2.0", | ||
"docz-theme-default": "1.2.0", | ||
"emotion-theming": "10.0.10", | ||
"emotion-theming": "10.0.14", | ||
"react": "16.8.6", | ||
"react-dom": "16.8.6", | ||
"typescript": "3.5.1" | ||
} | ||
"typescript": "3.5.3" | ||
}, | ||
"source": "dist-src/index.js", | ||
"types": "dist-types/index.d.ts", | ||
"main": "dist-node/index.js", | ||
"module": "dist-web/index.js" | ||
} |
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
6680
37
+ Addedhotkeys-js@3.6.12(transitive)
- Removedhotkeys-js@3.6.11(transitive)
Updatedhotkeys-js@3.6.12