-
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
1a3e715
commit c6e0018
Showing
2 changed files
with
41 additions
and
6 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
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,42 @@ | ||
import React 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 = () => ( | ||
// <div className="App"> | ||
// <p className="App__message">The last pressed key is [Enter]</p> | ||
// </div> | ||
// ); | ||
type State = { | ||
putKey: string; | ||
}; | ||
|
||
export class App extends React.Component<State> { | ||
state: State = { | ||
putKey: '', | ||
}; | ||
|
||
handlePutKeyboard = (event: KeyboardEvent) => { | ||
this.setState({ putKey: event.key }); | ||
}; | ||
|
||
componentDidMount() { | ||
document.addEventListener('keyup', this.handlePutKeyboard); | ||
} | ||
|
||
componentWillUnmount() { | ||
document.removeEventListener('keyup', this.handlePutKeyboard); | ||
} | ||
|
||
render() { | ||
const { putKey } = this.state; | ||
|
||
return ( | ||
<div className="App"> | ||
<p className="App__message"> | ||
{putKey === '' | ||
? `Nothing was pressed yet` | ||
: `The last pressed key is [${putKey}]`} | ||
</p> | ||
</div> | ||
); | ||
} | ||
} |