Skip to content

Commit

Permalink
Revert "fix: remove unnecessary dependency"
Browse files Browse the repository at this point in the history
  • Loading branch information
parasharrajat authored Oct 16, 2023
1 parent b808ace commit 0912b7f
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 0912b7f

Please sign in to comment.