Last active
September 30, 2016 19:58
-
-
Save Breta01/99239311bcad19ec6075dbf8cf12dc0b to your computer and use it in GitHub Desktop.
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
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