From 0912b7f3da2bcf3a6b7bc41963bc95a6cdac4d54 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Mon, 16 Oct 2023 15:07:17 +0530 Subject: [PATCH] Revert "fix: remove unnecessary dependency" --- src/components/PopoverWithoutOverlay/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/PopoverWithoutOverlay/index.js b/src/components/PopoverWithoutOverlay/index.js index 3b194ad4b9cf..d35637958f1d 100644 --- a/src/components/PopoverWithoutOverlay/index.js +++ b/src/components/PopoverWithoutOverlay/index.js @@ -8,6 +8,7 @@ import styles from '../../styles/styles'; import * as StyleUtils from '../../styles/StyleUtils'; import getModalStyles from '../../styles/getModalStyles'; import withWindowDimensions from '../withWindowDimensions'; +import usePrevious from '../../hooks/usePrevious'; function Popover(props) { const {onOpen, close} = React.useContext(PopoverContext); @@ -24,6 +25,8 @@ function Popover(props) { props.outerStyle, ); + const prevIsVisible = usePrevious(props.isVisible); + React.useEffect(() => { if (props.isVisible) { props.onModalShow(); @@ -40,7 +43,7 @@ function Popover(props) { Modal.willAlertModalBecomeVisible(props.isVisible); // We prevent setting closeModal function to null when the component is invisible the first time it is rendered - if (!firstRenderRef.current || !props.isVisible) { + if (prevIsVisible === props.isVisible && (!firstRenderRef.current || !props.isVisible)) { firstRenderRef.current = false; return; } @@ -49,7 +52,7 @@ function Popover(props) { // We want this effect to run strictly ONLY when isVisible prop changes // eslint-disable-next-line react-hooks/exhaustive-deps - }, [props.isVisible]); + }, [props.isVisible, prevIsVisible]); if (!props.isVisible) { return null;