diff --git a/src/App.tsx b/src/App.tsx index f819cbdb9..43759d4fe 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,33 @@ -import React from 'react'; +import { Component } from 'react'; -export const App: React.FC = () => ( -
-

The last pressed key is [Enter]

-
-); +export class App extends Component { + state = { + pressedKey: '', + }; + + handleKeyUp = (event: KeyboardEvent) => { + this.setState({ pressedKey: event.key }); + }; + + componentDidMount(): void { + document.addEventListener('keyup', this.handleKeyUp); + } + + componentWillUnmount(): void { + document.removeEventListener('keyup', this.handleKeyUp); + } + + render() { + return ( +
+

+ {!this.state.pressedKey ? ( +

Nothing was pressed yet

+ ) : ( +

The last pressed key is [{this.state.pressedKey || 'None'}]

+ )} +

+
+ ); + } +}