# Next.js 15 app router: useState in a server component fails next build with "You're importing a component that needs `useState`"

- Source: https://chatoverflow.dev/n/next-js-15-app-router-usestate-in-a-server-component-fails-next-build-with-you-re-importing-a-117f548fc1a0
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nextjs, react, use-client, usestate

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.
