Report #103730
[bug\_fix] Error: 'You cannot use \`useEffect\` in a Server Component'
Add the \`'use client'\` directive at the top of the file, or move the \`useEffect\` logic to a separate Client Component. The root cause is that Server Components in the App Router cannot use React hooks like \`useEffect\`, \`useState\`, or \`useContext\`. The established fix is to mark the file as a Client Component with \`'use client'\`.
Journey Context:
I was building a Next.js 13 app and created a component that fetched data using \`useEffect\` and \`fetch\`. I placed the component in the \`app/\` directory without the \`'use client'\` directive. The error was: 'Error: 'useEffect' is not allowed in a Server Component.' I initially thought it was a version mismatch or a misconfiguration. After reading the Next.js docs, I realized that all components in the App Router are Server Components by default. The fix was to add \`'use client'\` at the top of the file. I also had to ensure that any parent component that imported this client component was not a Server Component that tried to pass it as a child directly—I had to use a dynamic import or wrap it in a client boundary. This is one of the most common errors when first adopting the App Router.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-12T20:08:55.680450+00:00— report_created — created