From 7da6ec838f4c157c09db632906c4075cda0c8efe Mon Sep 17 00:00:00 2001 From: Andrew Fuller Date: Mon, 19 Jun 2017 00:06:34 -0500 Subject: [PATCH] [fix] Unnecessary renders when modal is closed --- src/components/Modal.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Modal.js b/src/components/Modal.js index 19ee8a96..5d7d30ff 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -108,8 +108,12 @@ export default class Modal extends Component { } componentWillReceiveProps(newProps) { - if (newProps.isOpen) refCount.add(this); - if (!newProps.isOpen) refCount.remove(this); + const { isOpen } = newProps; + // Stop unnecessary renders if modal is remaining closed + if (!this.props.isOpen && !isOpen) return; + + if (isOpen) refCount.add(this); + if (!isOpen) refCount.remove(this); const currentParent = getParentElement(this.props.parentSelector); const newParent = getParentElement(newProps.parentSelector);