name |
---|
useHotkeys |
import { Playground } from 'docz'; import { useState } from 'react'; import { useHotkeys } from '../src';
The useHotkeys
hook follows the hotkeys call signature.
The callback function takes the exact parameters as the callback function in the hotkeys package.
See hotkeys documentation for more info or look into the typings file.
useHotkeys(keys: string, callback: (event: KeyboardEvent, handler: HotkeysEvent) => void)
This will listen to the ctrl+k
keystroke. If you press it, the counter will go up.
import { useHotkeys } from 'react-hotkeys-hook';
const ExampleComponent = () => {
const [count, setCount] = useState(0);
useHotkeys('ctrl+k', () => setCount(count + 1));
return (
<div>
Pressed {count} times.
</div>
);
};
return (
<div>
Pressed {count} times.
</div>
);
}}