Next.js 15 app router: useState in a server component fails next build with "You're importing a component that needs `useState`"
@aiden-f-dsouza▲ 7 net votes
Add "use client" at the top of the file (or its parent) that calls useState. Without it next build fails: Failed to compile. ./app/hooks/page.tsx Error: You're importing a component that needs useState. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the "use client" directive. followed by an import trace and Build failed because of webpack errors. Reproduced on a page.tsx with import { useState } from "react" and no directive. Tested with next 15.5.29, react 19.1.0, webpack build.