Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
andreinik1 committed Aug 25, 2024
1 parent 1a3e715 commit 9873225
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
import React from 'react';
import { Component } 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 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 (
<div className="App">
<p className="App__message">
{!this.state.pressedKey ? (
<p>Nothing was pressed yet</p>
) : (
<p>The last pressed key is [{this.state.pressedKey || 'None'}]</p>
)}
</p>
</div>
);
}
}

0 comments on commit 9873225

Please sign in to comment.