🧩Needs 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.
In Next.js, something that runs in the browser, like a button click or state (useState), was used in a server-only file.
🤔 Why does it happen?
- The file that uses things like useState, useEffect, or onClick doesn't have "use client" at the top
🔧 Try this
- Add "use client" as the very first line of the file that uses those features
- It's better to move just the interactive part into its own component and add it only there, not to the whole page
🤖 Ask your AI like this
I get the error below in Next.js. Please split out only the parts that need to run in the browser into a separate component, and add "use client" to that file to fix it. [Paste the full error here]
Replace the [ ] parts with your own situation, and paste the error with a few extra lines before and after it.
Related terms
Other errors in this group
- Tried to read an empty value (undefined)
Cannot read properties of undefined - Tried to run something that isn't a function
is not a function - Name not defined
ReferenceError: … is not defined - Response isn't JSON (Unexpected token)
Unexpected token '<' … is not valid JSON - Server and browser screens don't match (Hydration)
Hydration failed - Endless redrawing (Too many re-renders)
Too many re-renders - List items have no key
Each child in a list should have a unique "key" prop - A function keeps calling itself (call stack exceeded)
RangeError: Maximum call stack size exceeded - Tried to change another component while drawing
Cannot update a component while rendering a different component - Tried to show an object directly on screen
Objects are not valid as a React child - Browser features used on the server (window is not defined)
ReferenceError: window is not defined - A client component was made async
async/await is not yet supported in Client Components - Outside image address not allowed (next/image)
Invalid src prop … hostname is not configured under images - Needs to be wrapped in Suspense (useSearchParams)
useSearchParams() should be wrapped in a suspense boundary - Unhandled async error
Uncaught (in promise) - Couldn't read the date (Invalid Date)
Invalid Date - NaN shows up where a number should be
NaN