Error library

Next.js: React client hook in a Server Component

In the App Router, components are Server Components by default and can't use client hooks like useState or useEffect. Add 'use client' at the top of the file that uses the hook, or move the interactive part into a small client component.

Get this exact error fixed — $49 Quick FixFixed within scope, or we keep working until it is · Read-only access Not sure it's this error? $149 diagnosis

Cause: A hook that needs the browser runs in a component without the 'use client' directive.

How to fix it

  1. Find the component using the hook (the error points to it).
  2. Add 'use client' as the first line of that file.
  3. Keep data fetching in Server Components; pass data to the client component as props.
  4. Don't mark whole layouts as client unless needed.

Example

Illustrative example, not from a customer project.

+ 'use client'
  import { useEffect } from 'react'

FAQ

Does 'use client' hurt SEO?

Client Components are still prerendered to HTML; they just also hydrate in the browser.

Why did this appear after migrating to the App Router?

The Pages Router had no Server Components; the App Router defaults to them.

QUICK FIX · $49 · THIS ERROR ONLY

Get this exact error fixed — $49 Quick FixFixed within scope, or we keep working until it is · Read-only access Not sure it's this error? $149 diagnosis

One error, one root cause, fixed in your app. If it turns out bigger, we tell you before doing more, and your $49 is credited toward the fix, diagnosis or Launch Path if you book within 14 days. Fixing three? The 3-Error Pack is $119.

Bigger job: Getting the whole app live? Launch Path, $1,195 flat.

Built with Lovable, Bolt, Replit, Cursor or v0? See rescue by platform and the security checklist.

Check it yourself first, free

$49Fix this error