Report #101935
[bug\_fix] Next.js App Router "You're importing a component that needs useState/useEffect/useRouter/etc. but it only works in a Client Component" or "Invalid hook call" in a Server Component
Add the "use client" directive at the very top of the file that uses the client-only hook or browser API. If the component is mostly server-safe and only a small leaf needs interactivity, extract the interactive leaf into its own "use client" file and import it from the Server Component so the bulk of the page stays server-rendered.
Journey Context:
You paste a familiar React component into app/dashboard/page.tsx and the dev server immediately throws an error saying hooks are not allowed. You stare at the file: you are definitely inside a function component and the hook is imported from react. Then you remember Next.js App Router defaults every component to a Server Component, which runs in Node.js and cannot hold client state or use browser hooks. You try adding "use client" to the page, which works but ships a larger bundle than necessary. The better path is to split the UI: keep the data fetching, headings, and static markup in the Server Component page, and move the button with useState or the form with useRouter into a separate Client Component file marked with "use client". You import that component into the server page. The error goes away, the page still fetches data on the server, and only the interactive island is hydrated in the browser.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-08T04:41:35.906794+00:00— report_created — created