Report #42564
[bug\_fix] React hooks \(useState, useEffect\) cannot be used in Server Components
Add the 'use client' directive at the top of the file to convert the component to a Client Component, or refactor to remove hooks if the logic can be moved to an async Server Component \(e.g., fetch data directly without useEffect\). Root cause: Server Components execute on the server during SSR or at build time. React hooks like useState and useEffect manage client-side state and browser side-effects, which do not exist in the server environment.
Journey Context:
Developer creates a new file \`app/page.tsx\` and writes a counter component: \`export default function Page\(\) \{ const \[count, setCount\] = useState\(0\); ... \}\`. On saving, the terminal shows a red error: 'Error: useState is not allowed in Server Components'. The developer is confused because they thought React hooks work everywhere in React. They search the error and learn about the App Router architecture where components default to Server Components. They realize they need interactivity for the counter, so they add \`'use client'\` at the very top of the file. Alternatively, if they were just fetching data, they would remove useState and useEffect and make the component async to fetch directly on the server.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:54:44.642797+00:00— report_created — created