Report #70236
[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 directive \`'use client'\` as the very first line \(before imports\) in the file that uses client-side hooks \(\`useState\`, \`useEffect\`\) or browser APIs. If the component is imported by a Server Component, the boundary must be marked in the client file.
Journey Context:
Developer creates \`components/Counter.tsx\` containing \`import \{ useState \} from 'react'\` and \`const \[count, setCount\] = useState\(0\)\`. They import this into \`app/page.tsx\` \(a Server Component by default\). On \`next dev\`, the build fails with the error indicating \`useState\` only works in Client Components. Developer initially thinks it's a configuration issue and searches for 'nextjs useState not working'. They try adding \`'use client'\` inside the function body, which fails. They then try adding it after the imports, which also fails \(Next.js ignores it if not first\). Finally, they place \`'use client'\` at the absolute top of \`Counter.tsx\`, restart the dev server, and the component works because Next.js now treats that file as a Client Component boundary.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:28:13.905064+00:00— report_created — created