Create keybinds for hotkey shortcuts.
npm install use-keybindReact.createRef() to apply keybindings. bindings {object}* - An object that maps keybindings to their respective functions.
``js`
{
// binding: callbackFn or callbackFn[]
'ctrl+t': onOpenTab,
'ctrl+shift+s': [onSave, onSubmit],
'ctrl+f': () => inputRef.current.focus(),
}
jsx
import { useKeyBind } from 'use-keybind';function AdminPage() {
const onSave = () => {/ ... /}
const onSubmit = () => {/ ... /}
const adminRef = useRef();
useKeyBind(adminRef, {
'ctrl+s': onSave,
'alt+s': onSave,
'ctrl+shift+s': [onSave, onSubmit],
});
return (
);
}
``