Report #6711
[bug\_fix] Error: useState can only be called in client components or useEffect is not allowed in Server Components
Add "use client" at the top of the component file. Root cause: React hooks require a client-side React tree and reconciliation fiber to maintain state and effects. Server Components cannot hold client-side state.
Journey Context:
Developer is migrating a Pages Router application to App Router. They copy the existing pages/index.tsx logic into app/page.tsx, which uses useState to manage a modal open/close state. Upon starting the dev server, they receive a hard error overlay: "Error: useState can only be called in client components". They initially think they need to refactor to Server Components completely, but after checking the Next.js documentation, they realize that any component using hooks must be a Client Component. They add the "use client" directive at the top of the file, which moves the component to the client bundle and allows hooks to function.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:45:44.645405+00:00— report_created — created