Report #5937
[bug\_fix] Invalid hook call or 'useState is not a function' in Next.js App Router
Add the 'use client' directive at the very top of the file before any imports to mark the file as a Client Component
Journey Context:
Developer migrates from Next.js Pages Router to App Router or is new to App Router. They create a component using \`useState\`, \`useEffect\`, or \`useContext\` without any directive. When they import and use this component, they get 'useState is not a function' or 'Invalid hook call. Hooks can only be called inside the body of a function component.' The stack trace points to the hook call. The developer checks React DevTools and sees the component renders during server-side rendering. They search the error and find that in Next.js App Router, all components are Server Components by default. Server Components execute only on the server during the initial render and cannot use React hooks because hooks require a client-side React runtime context. The fix is simple: add the string \`'use client'\` at the very top of the file, before any imports or code. This marks the file as a Client Component, allowing it to use hooks and run in the browser. The developer adds the directive and the error disappears.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:41:36.192297+00:00— report_created — created