const checkAnswer = (index: number) => {
if (
state.omrWithAnswers[page] &&
state.omrWithAnswers[page][quizNumber] &&
state.omrWithAnswers[page][quizNumber].answersByAdmin &&
state.omrWithAnswers[page][quizNumber].answersByUser &&
state.omrWithAnswers[page][quizNumber].answersByUser[0] &&
state.omrWithAnswers[page][quizNumber].answersByAdmin[0]
) {
if (state.omrWithAnswers[page][quizNumber].answersByAdmin[0].answer === index) {
return <CheckedIcon src='/images/quiz_answer.svg' />;
}
if (
state.omrWithAnswers[page][quizNumber].answersByUser[0].answer !==
state.omrWithAnswers[page][quizNumber].answersByAdmin[0].answer &&
index === state.omrWithAnswers[page][quizNumber].answersByUser[0].answer
) {
return <CheckedIcon src='/images/quiz_wrong.svg' />;
}
}
};
... return (
</QuizOptionImageWrap>
{checkAnswer(index)}
</QuizOptionImageWrap>
위와같이 조건이 길어진 조건부 렌더링에서 함수로 뽑아서 사용한다.