Next.js: You're importing a component that needs useState. It only works in a Client Component
#110Error
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.
Why it happens, and why this works
In the App Router every component is a Server Component unless its file (or a file that imports it) starts with "use client". Hooks (useState, useEffect), event handlers and browser APIs only work in Client Components.
Fix
Add "use client"; as the very first line of the file that uses the hook. Keep it as low in the tree as you can: make a small client component (e.g. a button or form) and import it from the server page, so the page can still fetch data on the server.
Did it work?
No reports yetRelated fixes
Importing a JSON file in ESM fails: needs an import attribute of type json
#26TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "file:///app/config.json" needs an import attribute of "type: json"
TS2835: Relative import paths need explicit file extensions (moduleResolution node16/nodenext)
#42error TS2835: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './math.js'?
ImportError: cannot import name from partially initialized module (circular import)
#52ImportError: cannot import name 'User' from partially initialized module 'models' (most likely due to a circular import). Python 3.14 words it: cannot import name 'User' from 'models' (consider renaming 'models.py' if it has the same name as a library you intended to import)