From c87b8f90c1cb7ace912c4a950a3beef2f1a55246 Mon Sep 17 00:00:00 2001 From: Jamie Halvorson Date: Thu, 19 Jul 2018 17:06:15 +0100 Subject: [PATCH] remove the resize event listener when the component unmounts, may cause a memory leak --- package.json | 2 +- src/provider.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 409748a..0838648 100644 --- a/package.json +++ b/package.json @@ -49,4 +49,4 @@ "webpack-cli": "^2.0.10", "webpack-merge": "^4.1.2" } -} \ No newline at end of file +} diff --git a/src/provider.js b/src/provider.js index bc57ed3..4e96a74 100644 --- a/src/provider.js +++ b/src/provider.js @@ -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)