Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-hotkeys-hook

Package Overview
Dependencies
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hotkeys-hook - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

4

dist-types/index.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc