Report #76537
[bug\_fix] Error: useState is not a function or Hook called in function which is neither a React function component nor a custom React Hook function \(in Server Component\)
Add the 'use client' directive at the very top of the file \(before any imports\) that uses client-side React hooks \(useState, useEffect, etc.\) or browser APIs. This opts the file into the Client Component boundary.
Journey Context:
Developer creates a new file app/components/Counter.tsx containing useState and onClick handlers. They import this into a page in the App Router \(app/page.tsx\). Immediately, the build fails or the dev server shows an error stating that hooks cannot be used in Server Components. The developer checks their imports and confirms they imported useState from 'react'. They suspect a corrupt node\_modules and reinstalls, but the error persists. They search the error and discover that Next.js App Router defaults to React Server Components, which cannot use browser-only APIs or hooks. They realize that 'use client' is a directive that tells Next.js to treat the file as a Client Component, bundling it for browser execution. Placing 'use client' at the top of Counter.tsx resolves the error because it creates a client boundary, allowing hooks to run in the browser while the parent page can remain a Server Component.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T11:03:49.534368+00:00— report_created — created