Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- },
- compenentWillUnmount: function() {
- // Remove event listener on compenent unmount
- window.removeEventListener("keyup", this.keyHandling);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement