Report #7265
[bug\_fix] Error: useState only works in Client Components
Add the \`'use client'\` directive at the very top of the file \(before imports\) to mark the file as a Client Component, allowing React hooks to execute in the browser.
Journey Context:
Developer creates a new component in the Next.js App Router and imports \`useState\` from React. Immediately upon importing or using the component, they get an 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'..." Developer is confused because they thought all React components could use hooks. They learn that Next.js App Router uses Server Components by default, which execute only on the server and cannot have interactive state. They try adding \`'use client'\` but place it after imports or inside a function, which fails. They eventually place \`'use client'\` at the absolute top of the file \(above imports\), understanding this creates a boundary where everything below becomes client-executable JavaScript, allowing hooks to work in the browser during hydration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:15:22.674166+00:00— report_created — created