From 62d37f68d4a887f24c65f76563354c98abf2eb4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20La=20Scala?= Date: Tue, 18 Jun 2024 14:02:51 +0200 Subject: [PATCH] fix: update local state only at initialization --- src/modules/question-view/QuestionView.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/question-view/QuestionView.tsx b/src/modules/question-view/QuestionView.tsx index 62ce81ac..8fdb0a1d 100644 --- a/src/modules/question-view/QuestionView.tsx +++ b/src/modules/question-view/QuestionView.tsx @@ -46,6 +46,7 @@ const QuestionView = (): JSX.Element => { } = useUserAnswers(); const [answer, setAnswer] = useState(''); + const [isInit, setIsInit] = useState(false); const userAuthentified = useMemo( () => typeof memberId === 'string' && memberId.length > 0, @@ -54,8 +55,11 @@ const QuestionView = (): JSX.Element => { // Update the answer if the stored value change useEffect(() => { - setAnswer(userAnswer?.answer ?? ''); - }, [userAnswer]); + if (!isInit) { + setAnswer(userAnswer?.answer ?? ''); + setIsInit(true); + } + }, [isInit, userAnswer]); const answerStatus = useMemo(() => userAnswer?.status, [userAnswer?.status]); const showSubmitButton = useMemo(