Skip to content

Commit

Permalink
remove the resize event listener when the component unmounts, may cau…
Browse files Browse the repository at this point in the history
…se a memory leak
  • Loading branch information
Jamie Halvorson committed Jul 19, 2018
1 parent ac7bbf7 commit c87b8f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"webpack-cli": "^2.0.10",
"webpack-merge": "^4.1.2"
}
}
}
7 changes: 7 additions & 0 deletions src/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ export default class Provider extends Component {
this.tabs = document.querySelectorAll('a');

this.checkMobile();
this.handleDebouncedCheck();
}

componentWillUnmount() {
window.removeEventListener('resize', this.handleDebouncedCheck, true);
}

handleDebouncedCheck = () => {
window.addEventListener(
'resize',
debounce(() => this.checkMobile(this.props), 66)
Expand Down

0 comments on commit c87b8f9

Please sign in to comment.