From d8dcd61632df515f10a053282aa3a43bd48993d6 Mon Sep 17 00:00:00 2001 From: ErasoumZe Date: Mon, 6 Jan 2025 09:52:14 -0300 Subject: [PATCH] add task solution --- src/App.tsx | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index f819cbdb9..a172073d2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,25 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; -export const App: React.FC = () => ( -
-

The last pressed key is [Enter]

-
-); +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 ( +
+

+ {key ? `The last pressed key is [${key}]` : 'Nothing was pressed yet'} +

+
+ ); +};