Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
VladKugot committed Jul 8, 2024
1 parent 1a3e715 commit d222efa
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import React from 'react';

export const App: React.FC = () => (
<div className="App">
<p className="App__message">The last pressed key is [Enter]</p>
</div>
);
export class App extends React.Component{
state = {
lastKey: ''
}

handleKeyDown = (event: KeyboardEvent) => {
this.setState({ lastKey: event.key });
};

componentDidMount() {
document.addEventListener('keyup', this.handleKeyDown);
}

render() {

const {lastKey} = this.state

return (
<div className="App">
{lastKey ?
(<p className="App__message">The last pressed key is [{lastKey}]</p>)
:
(<p className="App__message">Nothing was pressed yet</p>)}
</div>
)
}
}

0 comments on commit d222efa

Please sign in to comment.