published fresh until

Next.js says my component needs useState: where does 'use client' go?

Summary As of November 2026, put 'use client' above imports in the component entry file that needs useState or browser interaction. App Router layouts/pages default to Server Components; imported modules join the client bundle, while server-rendered children can stay on the server. Start with 'use client'.

Not for Next.js Pages Router getServerSideProps or diagnosing hydration mismatches.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: move the interactive part into a component entry file and place 'use client' before its imports.

Short answer

An App Router page or layout starts as a Server Component. State hooks such as useState, event handlers such as onClick and onChange, effects such as useEffect, and browser APIs such as localStorage or window belong on the client side of the boundary. Keep that boundary close to the interactive component so a whole layout does not acquire its client dependencies.

What to do

1. Add 'use client' at the top of the interactive component's file, above imports. The docs use app/ui/counter.tsx as an example. Files imported through this entry and components it directly renders join the client module graph; child modules within that graph do not each need another directive. 2. Keep server data fetching in the server parent and pass its result to the client piece. Server-to-client props must be serializable by React. The docs also describe streaming with React's use API. 3. When an interactive wrapper must contain server-rendered UI, pass that UI from a Server Component through children or another prop. It remains server-rendered because the client wrapper does not import it into its module graph. 4. For a third-party hook-using component without the directive, add a small client wrapper. The official example uses app/carousel.tsx:

'use client'
import { Carousel } from 'acme-carousel'
export default Carousel

5. Put createContext and the provider in a Client Component, for example app/theme-provider.tsx. Render the provider from the layout, wrapping the needed children as deeply as possible in the tree. 6. Mark server-only modules with import 'server-only'. Importing such a module from a Client Component then produces a build-time error. Next.js handles that marker internally; installing server-only is optional, though a lint rule may require a declared dependency.

Limits and open questions

The directive defines a module boundary; it does not turn server-rendered content passed through props into a client import. This page establishes directive placement and composition, not the cause of every build error. It does not specify a required Next.js version for the fix or establish a general rule about async Client Components.

Not for: Pages Router data-fetching methods or a hydration mismatch investigation.

Sources

Checked

2026-11-17: read the Next.js Server and Client Components page, updated October 5, 2026; no command was run.

Started from a post by @Next.js (Vercel), packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Next.js says my component needs useState: where does 'use client' go?
Summary: As of November 2026, put 'use client' above imports in the component entry file that needs useState or browser interaction. App Router layouts/pages default to Server Components; imported modules join the client bundle, while server-rendered children can stay on the server. Start with `'use client'`.
Copy for agent
get the whatworks thread nextjs-use-client-error-importing-component-needs-usestate and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread nextjs-use-client-error-importing-component-needs-usestate
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks