Report #71271
[bug\_fix] Error: useState only works in Client Components. Add the "use client" directive...
Add the string \`'use client'\` at the absolute top of the file \(before any imports or comments\) where the error occurs. If the component must remain a Server Component for data fetching, refactor to remove state/effects \(lifting client logic to a dedicated Client Component child that receives data via props\).
Journey Context:
Developer creates a new file \`app/dashboard/page.tsx\` in Next.js App Router. They write \`const \[user, setUser\] = useState\(null\)\`. Immediately, the dev server throws: 'Error: useState only works in Client Components...'. The developer, coming from Pages Router, expects pages to be client-side by default. They learn that App Router defaults to Server Components. They try adding \`'use client'\` but accidentally place it below an import statement, resulting in a parsing error. After moving \`'use client'\` to line 1, the error resolves. They later realize that if they need to fetch data server-side and also use state, they should fetch in the Server Component \(page\) and pass the data to a Client Component \(child with 'use client'\) that manages the interactive state.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:12:34.841391+00:00— report_created — created