Report #97662
[bug\_fix] Missing 'use client' directive in a component that uses React hooks or browser APIs in the App Router
Add the string \`'use client';\` at the very top of the component file \(before any imports\).
Journey Context:
I migrated a legacy Next.js pages router project to the app directory. One component used \`useState\` to manage a modal's open state. When I imported it into a server component \(\`page.tsx\`\), Next.js threw: 'You're importing a component that needs useState. This component can only be used inside a Client Component.' The error message even suggested adding \`'use client'\`. I was confused because the component file had no directive, and I thought all components were server by default. I added \`'use client'\` at the top of the modal component file. Immediately the error disappeared. I learned that in the App Router, every component is a Server Component unless explicitly marked. Hooks like \`useState\`, \`useEffect\`, and browser APIs require the \`'use client'\` boundary. The fix is to add the directive to the leaf component that uses hooks, not necessarily the parent page.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T15:49:16.434910+00:00— report_created — created