Skip to content

Commit

Permalink
fix: use only emptiness of answer to assess if previous state was filled
Browse files Browse the repository at this point in the history
  • Loading branch information
swouf committed Jun 19, 2024
1 parent 329a10d commit 303763f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/modules/question-view/QuestionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const QuestionView = (): JSX.Element => {
} = useUserAnswers();

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

const userAuthentified = useMemo(
() => typeof memberId === 'string' && memberId.length > 0,
Expand All @@ -56,11 +56,10 @@ const QuestionView = (): JSX.Element => {

// Update the answer if the stored value change
useEffect(() => {
if (!isInit && status === 'success' && answer.length === 0) {
if (status === 'success' && answer.length === 0) {
setAnswer(userAnswer?.answer ?? '');
setIsInit(true);
}
}, [answer.length, isInit, status, userAnswer]);
}, [answer.length, status, userAnswer]);
const answerStatus = useMemo(() => userAnswer?.status, [userAnswer?.status]);

const showSubmitButton = useMemo(
Expand Down

0 comments on commit 303763f

Please sign in to comment.