From ff18f61764900204ddf1f8ccbdb2db74af2ba1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cecilia=20Garc=C3=ADa?= Date: Fri, 15 Jun 2018 12:47:48 +0200 Subject: [PATCH] fix: Prevent component from being updated after it gets unmounted (#49) Prevents container dimensions from being updated after it gets unmounted Fixes #48 --- src/index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 6e60f82..26dfcfd 100644 --- a/src/index.js +++ b/src/index.js @@ -30,19 +30,23 @@ export default class ContainerDimensions extends Component { callOnAdd: false }) this.elementResizeDetector.listenTo(this.parentNode, this.onResize) + this.componentIsMounted = true this.onResize() } componentWillUnmount() { + this.componentIsMounted = false this.elementResizeDetector.uninstall(this.parentNode) } onResize() { const clientRect = ContainerDimensions.getDomNodeDimensions(this.parentNode) - this.setState({ - initiated: true, - ...clientRect - }) + if (this.componentIsMounted) { + this.setState({ + initiated: true, + ...clientRect + }) + } } render() {