Report #103434
[bug\_fix] TypeError: createContext only works in Client Components, or useState/useEffect is not allowed in a Server Component.
Add the 'use client' directive at the very top of the file that defines or directly uses the client-only API. Prefer extracting the interactive surface into a leaf Client Component and keep the page/layout as a Server Component so you can still export metadata and fetch data on the server.
Journey Context:
You install a UI library and import a Button in app/page.tsx. The dev server crashes with createContext only works in Client Components. You try adding 'use client' to the page, which fixes the crash but now you cannot export metadata and the whole page ships to the browser. The root cause is that Server Components cannot maintain React context or state; only Client Components can. The established fix is to isolate the client-only code: put the Button or provider in its own file with 'use client', then import it into a Server Component page. This keeps the server/client boundary at the leaves and preserves the benefits of Server Components.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-11T04:23:23.050801+00:00— report_created — created