← All errors · Next.js
You're importing a component that needs useState. It only works in a Client Component
Exact error
You're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
What it means
In the App Router every component is a Server Component unless marked otherwise. Hooks like useState, useEffect and event handlers only work in Client Components.
Likely causes
- Using React hooks in a file under app/ without the "use client" directive.
- Passing onClick or other handlers from a Server Component.
How to fix it
Add the directive as the very first line of the file that uses hooks:
'use client'; import { useState } from 'react'; export default function Counter() { const [n, setN] = useState(0); return <button onClick={() => setN(n + 1)}>{n}</button>; }Keep "use client" as low in the tree as possible: extract the interactive part into its own small component and import it from the Server Component page.
Related errors
- async/await is not yet supported in Client Components
- Hydration failed because the initial UI does not match what was rendered on the server
Get new fixes weekly
No spam. Unsubscribe anytime. Privacy