@letslearn/usehotkey

0.0.4 • Public • Published

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.

Package Sidebar

Install

npm i @letslearn/usehotkey

Weekly Downloads

0

Version

0.0.4

License

MIT

Unpacked Size

5.75 kB

Total Files

5

Last publish

Collaborators

  • saravanan10393