Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
manch0ffline committed Aug 16, 2024
1 parent 1a3e715 commit e139767
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 122 deletions.
184 changes: 68 additions & 116 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@mate-academy/eslint-config-react-typescript": "latest",
"@mate-academy/scripts": "^1.7.9",
"@mate-academy/scripts": "^1.9.3",
"@mate-academy/students-ts-config": "latest",
"@mate-academy/stylelint-config": "latest",
"@types/node": "^16.18.80",
Expand Down
40 changes: 35 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
import React from 'react';

export const App: React.FC = () => (
<div className="App">
<p className="App__message">The last pressed key is [Enter]</p>
</div>
);
type State = {
currentButton: string;
};

export class App extends React.Component<{}, State> {
state: Readonly<State> = {
currentButton: '',
};

handlePressKey = (event: KeyboardEvent) => {
this.setState({ currentButton: event.key });
};

componentDidMount(): void {
document.addEventListener('keyup', this.handlePressKey);
}

componentWillUnmount(): void {
document.removeEventListener('keyup', this.handlePressKey);
}

render() {
const { currentButton } = this.state;

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

0 comments on commit e139767

Please sign in to comment.