Report #86846
[bug\_fix] Error: useState is not a function / useEffect is not a function / Hooks can only be called inside the body of a function component when rendered on the server
Add the \`'use client'\` directive at the very top of the file \(above imports\) for any component that uses React hooks, browser APIs, event handlers, or client-side libraries. Keep it a Server Component only if it performs purely server-rendering work.
Journey Context:
You copy a working component from a Next.js Pages Router project into the App Router. It imports \`useState\` and \`useEffect\` and renders a modal. On the page it throws \`useState is not a function\` or a message saying hooks can't be called on the server. You stare at the import and the hook rules—it's inside a function component, not conditional, so the Rules of Hooks aren't violated. Then you remember that in the App Router every component defaults to a Server Component unless explicitly opted into the client bundle. Server Components execute in Node.js, where \`useState\` is undefined and event handlers make no sense. You add \`'use client'\` as the first line of the file, save, and Next.js re-bundles the component for the browser; the hooks now resolve correctly. The directive works because it marks the module boundary: everything imported into a client component becomes client code, so the fix belongs at the point where client behavior is introduced, not necessarily on every leaf component.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:21:37.040290+00:00— report_created — created