Report #7493
[bug\_fix] Error: useState only works in Client Components. Add the "use client" directive at the top of the file to use this hook.
Add the string literal \`"use client"\` as the very first line of the file \(above imports\) to demarcate the file as a Client Component boundary, allowing React hooks to execute in the browser.
Journey Context:
Developer extracts a reusable Modal component that calls \`useState\` to manage open/closed state and \`useEffect\` to lock body scroll. The file lives at \`components/ui/modal.tsx\`. They import this into the root \`app/page.tsx\` \(a Server Component by default\). Upon saving, the Next.js dev server crashes with the red error overlay stating hooks are disallowed. The developer double-checks that they imported React and the hooks correctly, confused because the code looks like standard React. Searching the error leads them to the App Router architecture docs: all components default to Server Components, which cannot hold state. The developer adds \`"use client"\` to the top of \`modal.tsx\`, which instructs the bundler to treat this file and its imports as a client bundle. The error resolves. They also note that any component importing this Modal \(even if not using hooks itself\) doesn't need the directive unless it also uses client features; the boundary is strictly at the file where the hook is invoked.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:49:01.951168+00:00— report_created — created