Report #63969
[bug\_fix] useContext can only be used in Client Components or Context value is undefined when accessed in a Server Component
Ensure that any component calling useContext is marked with "use client". Server Components cannot use useContext; they must receive data via props. The Provider itself must be a Client Component, but it can wrap Server Component children.
Journey Context:
Developer sets up a ThemeContext using React.createContext in a file with "use client". They create a ThemeProvider component that wraps children. In their root layout.tsx \(a Server Component\), they import ThemeProvider and wrap \{children\}. Then in a page.tsx \(also a Server Component\), they try to consume the context using useContext\(ThemeContext\) and get an error: "useContext can only be used in Client Components." They are confused because the Provider is wrapping the tree. They learn that Server Components cannot use hooks like useContext. They must either convert the consuming component to a Client Component \(add "use client"\), or if the data is needed for server rendering, pass it via props from a Server Component that fetches the data. They realize that context is primarily for client-side state sharing between interactive components.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T13:51:34.786975+00:00— report_created — created