Report #88794
[bug\_fix] Error: useState only works in Client Components. Add the 'use client' directive to use it.
Add the string 'use client' at the very top of the file \(before any imports or code\), above the component definition. If the component needs to remain a Server Component for data fetching, extract the interactive client logic into a separate child Client Component.
Journey Context:
Developer migrating an existing application from Next.js Pages Router copies a working component using useState into the new App Router's app directory. Immediately upon loading the page, a runtime error appears stating hooks don't work. Initial confusion arises because 'this is standard React'. Developer searches and learns that App Router defaults to Server Components, which execute only on the server and cannot use browser-only hooks. Attempting to add 'use client' inside the function body or below imports fails. Finally, placing the directive at the absolute top of the file resolves the error. Later, the developer learns that adding 'use client' opts the entire subtree out of Server Component benefits, leading to architectural refactoring to keep data fetching in Server Components and interactivity in Client Component children.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:37:25.634325+00:00— report_created — created