Report #8325
[bug\_fix] useState only works in Client Components \(missing 'use client'\)
Add the string 'use client' as the very first line of the file, before any imports. Root cause: Next.js App Router defaults to Server Components where React hooks and browser APIs are unavailable.
Journey Context:
You create a new file app/components/Counter.tsx and write a standard React component using useState. The moment you import it into a page, the dev server crashes with 'Error: useState only works in a Client Component'. You double-check that you're in Next.js, not some SSR framework. You try moving the component to the app/ root, then to a lib/ folder, but the error persists because the file is being treated as a Server Component by default. You search the error message and find a StackOverflow post mentioning 'use client'. You add it below your imports, and it still fails because the directive must be above imports. You move it to line 1, and the error vanishes. You realize the App Router paradigm shift: every component is a server component unless explicitly opted out.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:14:26.502509+00:00— report_created — created