Introduction
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
npm install react-keyboardconst keyMap = {
cmdK: {
combo: 'command+k',
eventType: 'keyup',
},
deleteNode: ['del', 'backspace'],
left: 'left',
}import { HotKeys, Handlers } from 'react-keyboard'
export class MyHotKeys extends React.Component {
showDocumentation = () => {
console.log('show doc')
}
deleteNode = () => {
console.log('deleted')
}
moveLeft = () => {
console.log('move left')
}
showChildDocumentation = () => {
console.log('show child doc')
}
handlersParent = {
cmdK: this.showDocumentation,
deleteNode: this.deleteNode,
}
handlersChild = {
cmdK: this.showChildDocumentation,
left: this.moveLeft,
}
render() {
return <HotKeys keyMap={keyMap} handlers={this.handlersParent}>
<span>this is my hotkeys</span>
<HotKeys handlers={this.handlersChild}>A child</HotKeys>
</HotKeys>
}
}