Report #14343
[bug\_fix] You're importing a component that needs useState/useEffect but it's being treated as a Server Component, causing errors like 'useState is not a function' or 'Hooks can only be called inside the body of a function component'
Add the 'use client' directive at the very top of the file \(before imports\). Root cause: Next.js App Router defaults all components to Server Components which run only on the server; hooks like useState/useEffect require client-side JavaScript and must be in Client Components marked with this directive to indicate they need browser execution.
Journey Context:
You create a new component Button.tsx that uses useState to manage a hover state. You write: import \{ useState \} from 'react'; export function Button\(\) \{ const \[hover, setHover\] = useState\(false\); ... \}. You import it into a page.tsx in your App Router project. Immediately, you get a hard error saying 'useState is not defined' or 'Invalid hook call. Hooks can only be called inside of the body of a function component.' You check React DevTools and see the component isn't even mounting. You verify that React is properly installed and you're not accidentally importing from the wrong package. You search online and find discussions about React Server Components. You realize that in the App Router, components are Server Components by default, meaning they execute during the build or request on the server only, sending HTML to the client. Since hooks require a browser environment to manage state via React's internal fiber tree, they can't run on the server where there is no browser event loop or DOM. You find the Next.js documentation on Client Components which explains that any file using hooks, browser APIs, or event handlers must start with the exact string 'use client' at the top of the file, before any imports. You add 'use client' as the first line of Button.tsx. The error resolves immediately because Next.js now knows to treat this as a Client Component, sending the JavaScript bundle to the browser where React can execute the hooks properly on the client side.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:18:48.382397+00:00— report_created — created