Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished task #928

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
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 class App extends React.PureComponent {
state = {
pressedKey: '',
};

componentDidMount(): void {
document.addEventListener('keyup', (event: KeyboardEvent) => {
this.setState({ pressedKey: event.key });
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't unmount this, as you created a new arrow function here. Move this function to be a class method.

}

componentWillUnmount(): void {
document.removeEventListener('keyup', this.setState);
}

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