🧩use client가 필요함 (Next.js)
You're importing a component that needs "useState". This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the "use client" directive.
Next.js에서 버튼 클릭이나 상태(useState)처럼 브라우저에서 움직이는 기능을 서버용 파일에서 썼다는 뜻이에요.
🤔 왜 생기나요?
- useState, useEffect, onClick 같은 기능을 쓰는 파일 맨 위에 "use client"가 없어요
🔧 이렇게 해 보세요
- 그 기능을 쓰는 파일 맨 첫 줄에 "use client"를 넣어요
- 페이지 전체가 아니라 움직이는 부분만 따로 컴포넌트로 빼서, 거기에만 넣는 게 좋아요
🤖 AI에게 이렇게 물어보세요
Next.js에서 아래 에러가 나. 브라우저에서 동작해야 하는 부분만 별도 컴포넌트로 나누고, 그 파일에 "use client"를 넣어서 고쳐 줘. [여기에 에러 전체를 붙여 넣기]
[ ] 부분은 내 상황에 맞게 바꾸고, 에러는 앞뒤 몇 줄까지 넉넉히 복사해 붙여 넣으세요.
관련 용어
같은 분류의 다른 에러
- 비어 있는 값을 읽으려 함 (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 - 함수가 끝없이 자기 자신을 부름 (호출 스택 초과)
RangeError: Maximum call stack size exceeded - 그리는 도중에 다른 컴포넌트를 바꾸려 함
Cannot update a component while rendering a different component - 객체를 화면에 그대로 출력하려 함
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