Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ErasoumZe committed Jan 6, 2025
1 parent 7d49869 commit d8dcd61
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import React from 'react';
import React, { useEffect, useState } from 'react';

export const App: React.FC = () => (
<div className="App">
<p className="App__message">The last pressed key is [Enter]</p>
</div>
);
export const App: React.FC = () => {
const [key, setKey] = useState('');

useEffect(() => {
const handleKeyUp = (event: KeyboardEvent) => {
setKey(event.key);
};

document.addEventListener('keyup', handleKeyUp);

return () => {
document.removeEventListener('keyup', handleKeyUp);
};
}, []);

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

0 comments on commit d8dcd61

Please sign in to comment.