Last active
October 15, 2015 14:54
-
-
Save glortho/bcb280e6f18ac79666a7 to your computer and use it in GitHub Desktop.
Example of keydown decorator at https://github.com/jedverity/react-keydown/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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