1- import React , { useEffect , useState , ReactNode , useContext } from 'react' ;
1+ import React , { useEffect , useState , ReactNode , useContext , useRef } from 'react' ;
22import { createGlobalStyle } from 'styled-components' ;
33import { WidthProps } from 'styled-system' ;
44import { useIsEscKeyPressed } from '../../utils/hooks/useIsEscKeyPressed' ;
@@ -56,12 +56,13 @@ const ANIMATION_DURATION = Math.max(DIMMING_ANIMATION_DURATION, CARD_ANIMATION_D
5656const Modal : React . FC < ModalProps > = ( { children, onClose, dismissible, ...rest } : ModalProps ) => {
5757 const [ visible , setVisible ] = useState ( true ) ;
5858 const isEscKeyPressed = useIsEscKeyPressed ( ) ;
59+ const closeTimeout = useRef ( null ) ;
5960
6061 const handleClose : DismissFunc = ( ) => {
6162 setVisible ( false ) ;
6263
6364 if ( onClose ) {
64- setTimeout ( ( ) => onClose ( ) , ANIMATION_DURATION ) ;
65+ closeTimeout . current = setTimeout ( ( ) => onClose ( ) , ANIMATION_DURATION ) ;
6566 }
6667 } ;
6768
@@ -77,6 +78,13 @@ const Modal: React.FC<ModalProps> = ({ children, onClose, dismissible, ...rest }
7778 }
7879 } , [ dismissible , isEscKeyPressed ] ) ;
7980
81+ useEffect (
82+ ( ) => ( ) => {
83+ if ( closeTimeout . current ) clearTimeout ( closeTimeout . current ) ;
84+ } ,
85+ [ ]
86+ ) ;
87+
8088 const renderChildren = ( ) => {
8189 if ( typeof children === 'function' ) {
8290 return children ( handleClose ) ;
0 commit comments