react-key
v1.0.1
Published
Simple hotkeys mixin for React
Downloads
14
Maintainers
Readme
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)
// ...
}
})