Report #77229
[bug\_fix] 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"
Add the "use client" directive at the very top of the file \(before any imports\) that uses client-side features such as React hooks \(useState, useEffect\), browser APIs \(window, document\), or event handlers \(onClick\). Keep the parent tree as Server Components where possible to minimize bundle size.
Journey Context:
Developer creates a Button.tsx component with \`const \[count, setCount\] = useState\(0\)\` and uses it in \`app/page.tsx\`. On running \`next dev\`, the terminal shows the error about useState only working in Client Components. Developer initially tries adding "use client" inside the component function, which fails \(syntax error\). Then tries adding it below imports, which also fails. After reading the error link, developer learns the directive must be at the top of the file before imports. Moving "use client" to line 1 fixes it. Developer then realizes that data fetching should happen in a parent Server Component, passing data down to this Client Component via props, optimizing the architecture.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:13:20.691267+00:00— report_created — created