File size: 724 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---
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)