Report #104680
[bug\_fix] Unhandled Runtime Error: Error: This hook does not work in a server component. Use 'use client' at the top of the file.
Add the \`'use client'\` directive at the top of the file to mark it as a Client Component. Alternatively, move the hook usage to a separate client component and import it into the server component.
Journey Context:
While migrating a legacy React app to Next.js App Router, a developer tried to use \`useState\` in a layout component. The app crashed with the above error. They assumed all components could use hooks. After checking the Next.js documentation, they learned that by default all components in the App Router are Server Components, which cannot use hooks or event handlers. The fix was to add \`'use client'\` at the very top of the file \(before any imports\) to opt that component into client-side rendering. They also had to ensure that any child components that also used hooks were also marked as client components or refactored.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-27T20:09:26.162961+00:00— report_created — created