From a7b1ad2fee3621d276c27720fbe152a26841cf32 Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 19 May 2023 07:01:27 +0200 Subject: [PATCH] fix useEffect loop --- src/components/views/Board.jsx | 12 ++++++++++-- src/components/views/Thread.jsx | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index abffbede..5b0db722 100644 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -70,6 +70,7 @@ const Board = () => { const [prevScrollPos, setPrevScrollPos] = useState(0); const [visible, setVisible] = useState(true); const [triggerPublishComment, setTriggerPublishComment] = useState(false); + const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false); const [selectedFeed, setSelectedFeed] = useState(feed); const [rotatedStates, setRotatedStates] = useState({}); const [isImageSearchOpen, setIsImageSearchOpen] = useState(false); @@ -402,6 +403,8 @@ const Board = () => { default: break; } + + setTriggerPublishCommentEdit(true); }; @@ -414,8 +417,13 @@ const Board = () => { useEffect(() => { - publishCommentEdit(); - }, [publishCommentEditOptions, publishCommentEdit]); + if (publishCommentEditOptions && triggerPublishCommentEdit) { + (async () => { + await publishCommentEdit(); + setTriggerPublishCommentEdit(false); + })(); + } + }, [publishCommentEditOptions, triggerPublishCommentEdit, publishCommentEdit]); // desktop navbar board select functionality diff --git a/src/components/views/Thread.jsx b/src/components/views/Thread.jsx index a6cf4d36..851196f5 100644 --- a/src/components/views/Thread.jsx +++ b/src/components/views/Thread.jsx @@ -60,6 +60,7 @@ const Thread = () => { const replyMenuRefs = useRef({}); const [triggerPublishComment, setTriggerPublishComment] = useState(false); + const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false); const [errorMessage, setErrorMessage] = useState(null); const [successMessage, setSuccessMessage] = useState(null); const [isReplyOpen, setIsReplyOpen] = useState(false); @@ -375,6 +376,8 @@ const Thread = () => { default: break; } + + setTriggerPublishCommentEdit(true); }; @@ -387,8 +390,13 @@ const Thread = () => { useEffect(() => { - publishCommentEdit(); - }, [publishCommentEditOptions, publishCommentEdit]); + if (publishCommentEditOptions && triggerPublishCommentEdit) { + (async () => { + await publishCommentEdit(); + setTriggerPublishCommentEdit(false); + })(); + } + }, [publishCommentEditOptions, triggerPublishCommentEdit, publishCommentEdit]); // mobile navbar board select functionality const handleSelectChange = (event) => {