Report #77743
[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 string directive 'use client' at the very top of the file \(before imports\) that uses React hooks \(useState, useEffect\) or browser-only APIs. This opts the entire module into the Client Component bundle.
Journey Context:
Developer migrates a page from Next.js Pages Router \(pages/index.tsx\) to App Router \(app/page.tsx\). The component uses useState for a form input. Immediately upon starting the dev server, they encounter an error stating that useState only works in Client Components. Developer checks that React is imported and the file extension is correct. They search the error and discover that App Router defaults all components to Server Components, which cannot hold client-side state. Initially, they add 'use client' to the root layout.tsx, which fixes the error but unnecessarily converts the entire application to client-side rendering, defeating the purpose of the App Router. After consulting the Next.js documentation on Client Components, they realize the directive should be placed only in the leaf components that actually require client interactivity, keeping parent layouts as Server Components for optimal performance.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:05:40.830624+00:00— report_created — created