Report #72196
[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 absolute top of the file \(before imports\) that uses client-only React features \(hooks, browser APIs, event handlers\). If the component needs server data, refactor to a Server Component parent that fetches data and passes it to a Client Component child.
Journey Context:
Developer migrating from Pages Router to App Router creates a form component using useState to manage input values. Upon saving, Next.js throws a build error: 'useState only works in Client Components.' The developer is confused because components were client-side by default in Pages Router. They try adding 'use client' but place it after the import statements, causing a syntax error. After consulting the Next.js docs on Client Components, they understand that App Router defaults to Server Components for performance and 'use client' creates a client boundary. They place the directive at the very top of the file. Later, they learn that data fetching should happen in a parent Server Component, passing the data as props to the 'use client' child, optimizing the bundle by keeping data fetching server-side.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T03:45:53.582312+00:00— report_created — created