🧩그리는 도중에 다른 컴포넌트를 바꾸려 함
Cannot update a component while rendering a different component
React가 화면을 그리는 도중에 다른 컴포넌트의 값을 바꾸려 해서 경고한 거예요.
🤔 왜 생기나요?
- 컴포넌트 본문에서 바로 부모의 setState를 불렀어요
- 그리는 중에 실행되는 코드에서 다른 상태를 바꿨어요
🔧 이렇게 해 보세요
- 값을 바꾸는 코드는 버튼 클릭 같은 이벤트나 useEffect 안으로 옮겨요
- 에러에 나온 두 컴포넌트 이름을 확인해요
🤖 AI에게 이렇게 물어보세요
React에서 'Cannot update a component while rendering a different component' 경고가 나. 렌더링 중에 상태를 바꾸는 곳을 찾아 이벤트나 useEffect로 옮겨 줘. [여기에 에러 전체를 붙여 넣기]
[ ] 부분은 내 상황에 맞게 바꾸고, 에러는 앞뒤 몇 줄까지 넉넉히 복사해 붙여 넣으세요.
관련 용어
같은 분류의 다른 에러
- 비어 있는 값을 읽으려 함 (undefined)
Cannot read properties of undefined - 함수가 아닌 것을 실행하려 함
is not a function - 정의되지 않은 이름
ReferenceError: … is not defined - JSON이 아닌 응답 (Unexpected token)
Unexpected token '<' … is not valid JSON - 서버 화면과 브라우저 화면이 다름 (Hydration)
Hydration failed - 무한 반복 그리기 (Too many re-renders)
Too many re-renders - 목록에 key가 없음
Each child in a list should have a unique "key" prop - use client가 필요함 (Next.js)
Add the "use client" directive - 함수가 끝없이 자기 자신을 부름 (호출 스택 초과)
RangeError: Maximum call stack size exceeded - 객체를 화면에 그대로 출력하려 함
Objects are not valid as a React child - 서버에서 브라우저 기능을 씀 (window is not defined)
ReferenceError: window is not defined - 클라이언트 컴포넌트를 async로 만듦
async/await is not yet supported in Client Components - 외부 이미지 주소가 허용되지 않음 (next/image)
Invalid src prop … hostname is not configured under images - Suspense로 감싸야 함 (useSearchParams)
useSearchParams() should be wrapped in a suspense boundary - 처리하지 않은 비동기 에러
Uncaught (in promise) - 날짜를 읽지 못함 (Invalid Date)
Invalid Date - 숫자 자리에 NaN이 나옴
NaN