1- import React , { useEffect } from "react" ;
1+ import React , { useEffect , useRef } from "react" ;
22import { useDispatch , useSelector } from "react-redux" ;
33import Modal from "./Modal" ;
44import { openModal } from "../../actions/ModalActions" ;
@@ -12,6 +12,8 @@ const FeedbackPopUp = () => {
1212 ) ;
1313 const feedbackPreference = useSelector ( ( state ) => state . user . askForFeedback ) ;
1414
15+ const timeoutRef = useRef ( ) ;
16+
1517 const closeModal = ( ) => {
1618 dispatch ( {
1719 type : "CLOSE_MODAL" ,
@@ -51,17 +53,21 @@ const FeedbackPopUp = () => {
5153
5254 // Show modal after delay if property layer is active
5355 useEffect ( ( ) => {
54- let timeoutId ;
56+ if ( timeoutRef . current ) {
57+ clearTimeout ( timeoutRef . current ) ;
58+ }
5559 if ( propertyLayerActive && feedbackPreference ) {
56- clearTimeout ( timeoutId ) ;
57- timeoutId = setTimeout ( ( ) => {
60+ timeoutRef . current = setTimeout ( ( ) => {
5861 dispatch ( openModal ( "feedbackPopUp" ) ) ;
5962 } , 300000 ) ;
6063 }
6164 return ( ) => {
62- clearTimeout ( timeoutId ) ;
65+ if ( timeoutRef . current ) {
66+ clearTimeout ( timeoutRef . current ) ;
67+ timeoutRef . current = null ;
68+ }
6369 } ;
64- } , [ propertyLayerActive ] ) ;
70+ } , [ propertyLayerActive , feedbackPreference ] ) ;
6571
6672 return (
6773 < Modal
0 commit comments