silverwolf-x/project / errors /context-in-server-component.mdx
silverwolf-x's picture
download
raw
724 Bytes
---
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)

Xet Storage Details

Size:
724 Bytes
·
Xet hash:
8dc9928bf01ebe0a933f51d89f3cc887aa5dad082bf5b52425e78e541789f716

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.