This repository has been archived by the owner on Jun 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
[BUG] 금융역량테스트 해설 언마운트 안되는 현상 #40
Labels
bug
Something isn't working
Comments
toothlessdev
assigned shgusgh12, seokiis and toothlessdev and unassigned shgusgh12, seokiis and toothlessdev
Jan 12, 2024
setTimeout(() => {
setIsCorrect(null);
setIsCommentVisible(true);
}, 2000);
이 부분에서 setTImeout cleanUp이 안되는 것 같은데, 다음 페이지 넘어갈 떄 cleanUp 해주면 안되나요? |
❎ 버그발생코드 const onChooseOptions = (index: number) => {
let selectedAnswer = "";
if (index === 0) selectedAnswer = "O";
else if (index === 1) selectedAnswer = "X";
else selectedAnswer = "";s
return () => {
if (selectedAnswer === answer) {
setIsCorrect(true);
} else {
setIsCorrect(false);
}
timeout.current = setTimeout(() => {
setIsCorrect(null);
setIsCommentVisible(true);
}, 2000);
};
};
const $options = document.querySelectorAll(`.${questionOptClassName}`);
for (let index = 0; index < $options.length; index++) {
$options[index].addEventListener("click", onChooseOptions(index));
} ✅ 수정된 코드 const onChooseOptions = (e: Event) => {
setIsCorrect(e.target?.innerHTML === answer);
timeout.current = setTimeout(() => {
setIsCommentVisible(true);
}, 2000);
};
const $options = document.querySelectorAll(`.${questionOptClassName}`);
for (let index = 0; index < $options.length; index++) {
$options[index].addEventListener("click", onChooseOptions);
} ✏️ 버그 원인 : 자바스크립트 함수 & 이벤트리스너 클로져 및 렉시컬 스코프 문제 🔗 참고자료 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
✏️ 버그 발생상황
✏️ 스크린샷
✏️ 추가 요구사항
정답선택 > 정답여부 표시 > 2초후 정답여부 사라짐 > 해설 보여줌
The text was updated successfully, but these errors were encountered: