Skip to content

Commit

Permalink
New Develop
Browse files Browse the repository at this point in the history
  • Loading branch information
vovan4ik1 committed Sep 27, 2024
1 parent 7d49869 commit a0e9b2a
Showing 1 changed file with 35 additions and 5 deletions.
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>
);
interface State {
PressedKey: string;
}

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

componentDidMount(): void {
document.addEventListener('keyup', (event: KeyboardEvent) => {
this.setState({ PressedKey: event.key });
});
}

componentWillUnmount() {
document.removeEventListener('keyup', (event: KeyboardEvent) => {
this.setState({ PressedKey: event.key });
});
}

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

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

0 comments on commit a0e9b2a

Please sign in to comment.