Report #100929
[bug\_fix] Build failure: missing 'use client' directive for a component using React hooks
Add \`'use client';\` at the very top of the file that contains hooks like \`useState\`, \`useEffect\`, or event handlers.
Journey Context:
A developer migrated a page from the Pages Router to the App Router. They had a \`ContactForm.tsx\` component using \`useState\` and \`onSubmit\`. No \`'use client'\` directive was present. The Next.js build failed with: 'Error: React Hook "useState" cannot be called in a class component. However, it's actually because the component is being treated as a Server Component by default in the App Router. The root cause: in the App Router, all components are Server Components by default; client-side features require explicit opt-in with \`'use client'\`. The fix: adding \`'use client'\` at the top of \`ContactForm.tsx\`. The developer also had to ensure that any parent importing this component was also a client component or that the import happened in a client boundary. The build succeeded after adding the directive.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T15:48:18.356990+00:00— report_created — created