File tree 1 file changed +5
-2
lines changed
src/components/PopoverWithoutOverlay
1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import styles from '../../styles/styles';
8
8
import * as StyleUtils from '../../styles/StyleUtils' ;
9
9
import getModalStyles from '../../styles/getModalStyles' ;
10
10
import withWindowDimensions from '../withWindowDimensions' ;
11
+ import usePrevious from '../../hooks/usePrevious' ;
11
12
12
13
function Popover ( props ) {
13
14
const { onOpen, close} = React . useContext ( PopoverContext ) ;
@@ -24,6 +25,8 @@ function Popover(props) {
24
25
props . outerStyle ,
25
26
) ;
26
27
28
+ const prevIsVisible = usePrevious ( props . isVisible ) ;
29
+
27
30
React . useEffect ( ( ) => {
28
31
if ( props . isVisible ) {
29
32
props . onModalShow ( ) ;
@@ -40,7 +43,7 @@ function Popover(props) {
40
43
Modal . willAlertModalBecomeVisible ( props . isVisible ) ;
41
44
42
45
// We prevent setting closeModal function to null when the component is invisible the first time it is rendered
43
- if ( ! firstRenderRef . current || ! props . isVisible ) {
46
+ if ( prevIsVisible === props . isVisible && ( ! firstRenderRef . current || ! props . isVisible ) ) {
44
47
firstRenderRef . current = false ;
45
48
return ;
46
49
}
@@ -49,7 +52,7 @@ function Popover(props) {
49
52
50
53
// We want this effect to run strictly ONLY when isVisible prop changes
51
54
// eslint-disable-next-line react-hooks/exhaustive-deps
52
- } , [ props . isVisible ] ) ;
55
+ } , [ props . isVisible , prevIsVisible ] ) ;
53
56
54
57
if ( ! props . isVisible ) {
55
58
return null ;
You can’t perform that action at this time.
0 commit comments