-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Solution #915
base: master
Are you sure you want to change the base?
Solution #915
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job:)
src/App.tsx
Outdated
} | ||
|
||
componentWillUnmount(): void { | ||
document.removeEventListener('keyup', this.handleKeyUp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not remove event listener
https://dev.to/marcostreng/how-to-really-remove-eventlisteners-in-react-3och
https://bobbyhadz.com/blog/react-remove-event-listener
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx 😊 as I understand I forgot to bind this, so it could add and remove the same function.
constructor(props){
super(props);
this.handleKeyUp = this.handleKeyUp.bind(this); //bind function once
}
Anyway, I rewrote it to the functional component, from the recommendations above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approve 🏁
DEMO LINK