최종 프로젝트 중간 점검에 앞서 각종 버그를 체크를했다.
녹음이 되는 기존 코드를 zustand로 전역관리를 해놔서 다행히 추가 코드 없이 바로 구현이 가능해서 다행이였던거 같다
// 컴포넌트가 unmount 될때 클리어 함수를 이용하여 초기화
return () => {
setRandomText([]); // 랜덤 문장 초기화
resetText(); // 텍스트 초기화
resetPercent();
resetTimer();
setIsDelay(false);
resetIndex();
};
}, []);
Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
해당 오류를 해결하기 위해 의존성 배열을 가지고 한번만 호출되게 하기 위해 useEffect를 사용하여 해결하였다 추후 조건문을 이용하여 함수 호출을 조정하였다
const handleIndex = () => {
if (index < 9) {
addIndex();
} else if (index === 9) {
handleUpsertScore();
setResult(true);
}
};