0.0.4 • Published 3 years ago

@letslearn/usehotkey v0.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

React hook for github's hotkey package.

  1. Install
npm i -S @letslearn/hotkey
  1. Usage in react hook
function KeyCount() {
  let [count, setCount] = React.useState(0);
  console.log("hotkey is comming ", useHotkey);
  let elementRef = useHotkey("h");
  return <h1 ref={elementRef} onClick={() => setCount(prev => prev + 1)}>Type h to count: {count}</h1>
}

By default, key shortcuts are registerd in global level, if you want to enable shortcut only when using is typing in particular element, we can scope out the when to fire the short cut

function KeyCount() {
  let elementRef = useHotkey("h", {scope: "root"});
}

Options

{
    scope: "string"
}

scope parameter takes the id of element to enable shortcuts inside element.