Skip to content

Commit 4b618c0

Browse files
authored
Update FeedbackPopUp > added useRef (#372)
1 parent b128145 commit 4b618c0

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/components/modals/FeedbackPopUp.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from "react";
1+
import React, { useEffect, useRef } from "react";
22
import { useDispatch, useSelector } from "react-redux";
33
import Modal from "./Modal";
44
import { 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

Comments
 (0)