react-hotkeys-hook
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -6,6 +6,6 @@ import hotkeys, { KeyHandler } from "hotkeys-js"; | ||
scope?: string; | ||
keyUp?: boolean; | ||
keyDown?: boolean; | ||
keyup?: boolean; | ||
keydown?: boolean; | ||
}; | ||
export declare function useHotkeys(keys: string, callback: KeyHandler, options?: Options, deps?: any[]): void; | ||
export {}; |
{ | ||
"name": "react-hotkeys-hook", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -24,19 +24,2 @@ # react-hotkeys-hook | ||
### Usage | ||
With TypeScript | ||
```typescript jsx | ||
import { useHotkeys } from 'react-hotkeys-hook'; | ||
export const ExampleComponent: React.FC = () => { | ||
const [count, setCount] = useState(0); | ||
useHotkeys('ctrl+k', () => setCount(prevCount => prevCount + 1)); | ||
return ( | ||
<p> | ||
Pressed {count} times. | ||
</p> | ||
); | ||
}; | ||
``` | ||
Or plain JS: | ||
```js | ||
@@ -62,6 +45,5 @@ export const ExampleComponent = () => { | ||
```typescript | ||
useHotkeys(keys: string, callback: (event: KeyboardEvent, handler: HotkeysEvent) => void, deps: any[] = []) | ||
useHotkeys(keys: string, callback: (event: KeyboardEvent, handler: HotkeysEvent) => void, options: Options = {}, deps: any[] = []) | ||
``` | ||
The `useHotkeys` hook follows the [hotkeys] call signature. | ||
The callback function takes the exact parameters as the callback function in the hotkeys package. | ||
@@ -77,2 +59,8 @@ See [hotkeys] documentation for more info or look into the typings file. | ||
to do this anymore by yourself. | ||
- `options: Options = {}` | ||
- `filter: (event: KeyboardEvent): boolean` is used to enable hotkeys inside input elements. Check out [hotkeys docs](https://github.com/jaywcjlove/hotkeys/#filter) for usage | ||
- `splitKey: string` is used to change the splitting character inside the keys argument. Default is `+`, but if you want | ||
to listen to the `+` character, you can set `splitKey` to i.e. `-` and listen for `ctrl-+` | ||
- `keyup: boolean` Determine if you want to listen on the keyup event | ||
- `keydown: boolean` Determine if want to listen on the keydown event | ||
- `deps: any[] = []`: The dependency array that gets appended to the memoisation of the callback. Here you define the inner | ||
@@ -79,0 +67,0 @@ dependencies of your callback. If for example your callback actions depend on a referentially unstable value or a value |
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
11276
92