Skip to content

Latest commit

 

History

History
32 lines (20 loc) · 729 Bytes

context-in-server-component.mdx

File metadata and controls

32 lines (20 loc) · 729 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
import { createContext } from 'react'

const Context = createContext()
After
'use client'
import { createContext } from 'react'

const Context = createContext()

Useful Links

Server and Client Components Composition Patterns