Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
VasylynaBC committed Oct 16, 2024
1 parent 7d49869 commit 7a29018
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
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 Props = {
keyType: string;
};

export class App extends React.Component<Props> {
state : Props= {
keyType:'',
}
handleKey = (event: KeyboardEvent) => {
this.setState({keyType: event.key})
}
componentDidMount() {
window.addEventListener('keyup', this.handleKey);
}
componentWillUnmount() {
window.removeEventListener('keyup', this.handleKey);
}
render() {
const { keyType } = this.state;
return (
<div className="App">
{keyType ? (
<p className="App__message">The last pressed key is [{keyType}]</p>
) : (
<p className="App__message">Nothing was pressed yet</p>
)}
</div>
);
}
};

0 comments on commit 7a29018

Please sign in to comment.