-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d49869
commit 00dc4f5
Showing
6 changed files
with
49 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import { Message } from './components/Message/'; | ||
|
||
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 [message, setMessage] = useState(''); | ||
|
||
return ( | ||
<div className="App"> | ||
<Message message={message} setMessage={setMessage} /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useEffect } from 'react'; | ||
|
||
interface Props { | ||
message: string; | ||
setMessage: (mes: string) => void; | ||
} | ||
|
||
export const Message: React.FC<Props> = ({ message, setMessage }) => { | ||
useEffect(() => { | ||
const handleKeyDown = (event: KeyboardEvent) => { | ||
if (event.key) { | ||
setMessage(event.key); | ||
} | ||
}; | ||
|
||
window.addEventListener('keydown', handleKeyDown); | ||
|
||
return () => { | ||
window.removeEventListener('keydown', handleKeyDown); | ||
}; | ||
}, []); | ||
Check warning on line 21 in src/components/Message/Message.tsx GitHub Actions / run_linter (20.x)
|
||
|
||
return ( | ||
<p className="App__message"> | ||
{message | ||
? `The last pressed key is [${message}]` | ||
: 'Nothing was pressed yet'} | ||
</p> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Message'; |