검색
검색
공개 노트 검색
회원가입로그인

react error 해결 하기 - Warning: Can't perform a React state update on an unmounted component.

다음과 같은 에러 메시지(워닝)가 떴다. 언마운트 된 컴포넌트에 상태 업데이트를 하려고 한다는 뜻이다.

next-dev.js?3515:20 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. at Image.

나의 경우 mode에 따라 컴포넌트를 바꿔가며 보여주고 있었다. 그런데 mode를 바꾼 후 바로 상태 업데이트를 하니 다음과 같은 경고가 떴다. 그래서 상태를 변경한 후 mode를 바꾸어주는 것으로 순서를 바꿨더니 해결됐다. 이렇게 하면 unmount가 뒤늦게 된다.

이 에러 생각보다 많이 나오는것 같다. next에서 코딩할 때 참고해 보자.

공유하기
카카오로 공유하기
페이스북 공유하기
트위터로 공유하기
url 복사하기
조회수 : 208
heart
T
페이지 기반 대답
AI Chat