React & Next.js errors · Error 05 of 7
Next.js: “needs useState … only works in a Client Component”
By Muhammad Abdullah, full-stack, mobile and ai automation developer · Last reviewed
You're importing a component that needs useState. This React Hook only works in a Client Component.Short answer
In the Next.js App Router, components are Server Components by default and cannot use hooks or browser APIs. Add "use client" at the top of the file that uses them, and keep that client component as small as possible.
Common causes
- Using
useState,useEffect, event handlers or browser APIs in a Server Component.
How to fix it
Mark the interactive component:
"use client"; import { useState } from "react";Keep data fetching in the server component and pass the data as props to the small client component.