Miss any of our Open RFC calls?Watch the recordings here! »

use-keyboard-shortcut

1.0.3 • Public • Published

useKeyboardShortcut

npm version

Click here for a small demo!

A custom React hook that allows adding keyboard shortcuts to a React application.

import React from 'react'
import useKeyboardShortcut from 'use-keyboard-shortcut'
 
const App = () => {
  useKeyboardShortcut(['Shift', 'H'], () => console.log('Shift + H has been pressed.'))
 
  return (
    <div>Hello World</div>
  )
}

For another example on how to use this hook, please see the example project

Documentation

useKeyboardShortcut(keysArray, callback)

keysArray should be an array of KeyboardEvent.key strings. A full list of strings can be seen here

callback should be a function that is called once the keys have been pressed.

Bugs / Problems

Please create an issue.

Install

npm i use-keyboard-shortcut

DownloadsWeekly Downloads

59

Version

1.0.3

License

MIT

Unpacked Size

516 kB

Total Files

19

Last publish

Collaborators

  • avatar