Files
vercel__next.js/errors/context-in-server-component.mdx
Delba de Oliveira 9c757f6d5c Docs IA 2.0: Server and Client Components (#79143)
Closes: 
- https://linear.app/vercel/issue/DOC-4655/client-components
- https://linear.app/vercel/issue/DOC-4656/server-components
- https://linear.app/vercel/issue/DOC-4657/composition-patterns

Redirects: https://github.com/vercel/front/pull/45564

This PR:

- Adds new **Server and Client Components** page to **Getting Started**
   - Explains how Server and Client components are rendered 
   - Clarifies when to use them
   - Reviews and simplifies composition patterns (examples)
- Improves the **How does PPR work** section in light of static,
dynamic, and streaming.
2025-05-15 14:26:19 +01:00

33 lines
724 B
Plaintext

---
title: createContext in a Server Component
---
## Why This Error Occurred
You are using `createContext` in a Server Component but it only works in Client Components.
## Possible Ways to Fix It
Mark the component using `createContext` as a Client Component by adding `'use client'` at the top of the file.
### Before
```jsx filename="app/example-component.js"
import { createContext } from 'react'
const Context = createContext()
```
### After
```jsx filename="app/example-component.js"
'use client'
import { createContext } from 'react'
const Context = createContext()
```
## Useful Links
- [Server and Client Components Composition Patterns](/docs/app/getting-started/server-and-client-components#examples)