Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
remove event listener on unmount and don't bind to avoid memory leak
Browse files Browse the repository at this point in the history
auditors: @bbondy
  • Loading branch information
bridiver committed Sep 16, 2016
1 parent 6802928 commit ad43443
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion js/components/contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const KeyCodes = require('../constants/keyCodes')

class ContextMenuItem extends ImmutableComponent {
componentDidMount () {
window.addEventListener('keydown', this.onKeyDown.bind(this))
window.addEventListener('keydown', this.onKeyDown)
}
componentWillUnmount () {
window.removeEventListener('keydown', this.onKeyDown)
}
onKeyDown (e) {
if (e.keyCode === KeyCodes.ESC || e.keyCode === KeyCodes.TAB) {
Expand Down

2 comments on commit ad43443

@bbondy
Copy link
Member

@bbondy bbondy commented on ad43443 Sep 18, 2016

Choose a reason for hiding this comment

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

++

@bsclifton
Copy link
Member

Choose a reason for hiding this comment

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

very nice! 😄

Please sign in to comment.