Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
A1eeex committed Oct 25, 2023
1 parent 1435b89 commit 0e8eb65
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 43 deletions.
41 changes: 35 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
import React from 'react';
import Message from './components/Message';

export const App: React.FC = () => (
<div className="App">
<Message />
</div>
);
type State = {
currentKey: string | null;
};

export class App extends React.Component {
state: State = {
currentKey: null,
};

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

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

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

return (
<div className="App">
<p className="App__message">
{currentKey
? `The last pressed key is[${currentKey}]`
: 'Nothing was pressed yet'}
</p>
</div>
);
}
}
37 changes: 0 additions & 37 deletions src/components/Message.tsx

This file was deleted.

0 comments on commit 0e8eb65

Please sign in to comment.