Skip to content

Instantly share code, notes, and snippets.

@glortho
Last active October 15, 2015 14:54
Show Gist options
  • Save glortho/bcb280e6f18ac79666a7 to your computer and use it in GitHub Desktop.
Save glortho/bcb280e6f18ac79666a7 to your computer and use it in GitHub Desktop.
Example of keydown decorator at https://github.com/jedverity/react-keydown/
class MyComponent extends React.Component {
@keydown('up')
goUp(event) {
event.preventDefault();
this.setState({ index: -1 });
}
}
// as a higher-order component
@keydown( 'up', 'down', 'shift+enter' )
class MyComponent extends React.Component {
componentWillReceiveProps( { keydown } ) {
if ( keydown.event ) {
console.log( keydown.event.which );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment