Skip to content

Commit

Permalink
Merge pull request #29663 from parasharrajat/revert-29251-fix/issue-2…
Browse files Browse the repository at this point in the history
…9159

Revert "fix: remove unnecessary dependency"
  • Loading branch information
tgolen authored Oct 17, 2023
2 parents 79ade92 + 0912b7f commit 5570eba
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/PopoverWithoutOverlay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -24,6 +25,8 @@ function Popover(props) {
props.outerStyle,
);

const prevIsVisible = usePrevious(props.isVisible);

React.useEffect(() => {
if (props.isVisible) {
props.onModalShow();
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit 5570eba

Please sign in to comment.