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

some commit message #1966

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"devDependencies": {
"@cypress/react18": "^2.0.1",
"@mate-academy/scripts": "^1.8.5",
"@mate-academy/scripts": "^2.1.0",
"@mate-academy/students-ts-config": "*",
"@mate-academy/stylelint-config": "*",
"@types/node": "^20.14.10",
Expand Down
36 changes: 32 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
import React from 'react';

export const App: React.FC = () => (
<div className="App">
<p className="App__message">The last pressed key is [Enter]</p>
type State = {
pressedKey: string;
}

export class App extends React.Component<{}, State> {

state: State = {
pressedKey: '',
};

componentDidMount(): void {
document.addEventListener('keyup', this.keyUpHandler);
}

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

keyUpHandler = (event: KeyboardEvent) => {
this.setState(prevState =>
prevState.pressedKey !== event.key ? { pressedKey: event.key } : null

Choose a reason for hiding this comment

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

The setState method is conditionally updating the state only if the pressed key is different from the previous one. If the same key is pressed consecutively, the state will not update, and the console will still log the key. If this is not the intended behavior, consider removing the condition to always update the state with the pressed key.

);

Check failure on line 24 in src/App.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

Unexpected console statement
console.log(event.key);
};

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