Report #35270
[bug\_fix] You're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with 'use client'
Add the 'use client' directive at the very top of the file \(before any imports\) that contains the client-side logic \(hooks, browser APIs, event listeners\). If only a small part needs client features, extract that into a separate file with 'use client' and import it into a Server Component. Root cause: Next.js App Router defaults to Server Components which run only on the server; React hooks like useState require a client component context to execute.
Journey Context:
Developer migrates a working page from Pages Router to App Router. The page contains a simple counter using useState. Upon starting the dev server, the screen shows an error overlay: 'useState only works in Client Components'. Developer is confused because the code worked perfectly in the old pages/ directory. They search the error and land on the Next.js docs explaining Server Components. They realize that in App Router, every component is a Server Component by default. They try adding 'use client' to the top of the file. The error disappears. Later, they refactor to keep the layout as a Server Component and move the interactive counter to a separate 'Counter.tsx' with 'use client', importing it into the page. This preserves server-side rendering for the static parts while hydrating only the interactive island.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T13:39:58.903813+00:00— report_created — created