class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
message: ''
};
this.handleEnter = this.handleEnter.bind(this);
this.handleKeyPress = this.handleKeyPress.bind(this);
}
// change code below this line
componentDidMount() {
document.addEventListener('keydown', handleKeyPress);
}
componentWillUnmount() {
document.removeEventListener('keydown', handleKeyPress);
}
// change code above this line
handleEnter() {
this.setState({
message: this.state.message + 'You pressed the enter key! '
});
}
handleKeyPress(event) {
if (event.keyCode === 13) {
this.handleEnter();
}
}
render() {
return (
<div>
<h1>{this.state.message}</h1>
</div>
);
}
};
Code Example |
---|
:: discord-buttons collector |
:: |
:: |
Javascript :: easyui datagrid scrollto |
Javascript :: How do you convert VARCHAR to TIMESTAMP |
:: |
:: |
Javascript :: |
Javascript :: jquery console.log object file |
:: |
Javascript :: browserslist |
:: trackpad scrolling detected multiple times |
:: |
Javascript :: |
Javascript :: |
:: how to angular html ts function |
Javascript :: discord javascript error on startup |
Javascript :: fabic js save and render |
Javascript :: |
Javascript :: likedislike mangodb |
Javascript :: |
Javascript :: |
Javascript :: rebuild package-lock.json |
Javascript :: |
Javascript :: npm ERR! peer react@"^15.x.x" from react-html-table-to-excel@2.0.0 |
:: |
Javascript :: change env location react |
:: |
:: |
:: |