/
githubmirror
/
next.js
Обзор
Документация
Войти
/
githubmirror
/
next.js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
canary
errors/context-in-server-component.mdx
32 строки
724 B
Delba de Oliveira
Docs IA 2.0: Server and Client Components (#79143)
15 май 2025, 16:26
Не верифицирован
15 май 2025, 16:26
9c757f6
Код
Авторство
О чём код?
--- 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)