Skip to content

Instantly share code, notes, and snippets.

@Breta01
Last active September 30, 2016 19:58
Show Gist options
  • Save Breta01/99239311bcad19ec6075dbf8cf12dc0b to your computer and use it in GitHub Desktop.
Save Breta01/99239311bcad19ec6075dbf8cf12dc0b to your computer and use it in GitHub Desktop.
import React from 'react';
const MyComponent = React.createClass({
render() {
return (
<h1>My Component</h1>
)
},
keyHandling: function(e) {
// Handle event
console.log("Key code: " + e.keyCode);
},
componentDidMount: function() {
// Add Event Listener on compenent mount
window.addEventListener("keyup", this.keyHandling);
},
componentWillUnmount: function() {
// Remove event listener on compenent unmount
window.removeEventListener("keyup", this.keyHandling);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment