Skip to content

Commit

Permalink
fix: update local state only at initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
swouf committed Jun 19, 2024
1 parent 721b8dc commit febf8ba
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/modules/question-view/QuestionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const QuestionView = (): JSX.Element => {
} = useUserAnswers();

const [answer, setAnswer] = useState<string>('');
const [isInit, setIsInit] = useState<boolean>(false);

const userAuthentified = useMemo(
() => typeof memberId === 'string' && memberId.length > 0,
Expand All @@ -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(
Expand Down

0 comments on commit febf8ba

Please sign in to comment.