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'} +

+
+ ); +};