1.0.1 • Published 9 years ago

react-key v1.0.1

Weekly downloads
23
License
GPL-2.0
Repository
github
Last release
9 years ago

react-key

Simple hotkeys mixin for React components.

npm i --save react-hotkey
var React = require('react')
var hotkeys = require('react-key')

var Component = React.createClass({
  // Simply add the mixin and you will have
  // access to ``this.bindKey(combo, fn)``.
  mixins: [hotkeys],

  // ProTip(tm): Bind your keys in ``componentWillMount``.
  // They are automagically removed when the component is unmounted.
  componentWillMount: function () {
    // For ``combo`` any valid key combination for keyboardjs will work.
    // For ``fn`` any method will work. The method will receive no parameters.
    this.bindKey('b', this.beep)
  },
  // ...
  beep: function () {
    // Preferably dispatch an action
    // Also, preferably this is the same method as you use for the
    // actual buttons that perform the same function (if applicable)
    // ...
  }
})