Open History to see the last commit
1'use client'
2β
3import { createContext, use } from 'react'
4import type { SlotImplementations } from './types'
5β
6export interface SlotContextValue {
7 implementations: SlotImplementations
8 strict: boolean
9}
10β
11const SlotContext = createContext<SlotContextValue | null>(null)
12β
13/**
14 * Hook to access slot implementations from within ClientSlot.
15 */
16export function useSlotContext(): SlotContextValue | null {
17 return use(SlotContext)
18}
19β
20export interface SlotProviderProps {
21 implementations: SlotImplementations
22 strict?: boolean
23 children?: React.ReactNode
24}
25β
26/**
27 * SlotProvider - makes slot implementations available to ClientSlot components.
28 *
29 * Must wrap the decoded RSC content so that ClientSlot components can
30 * access their slot implementations via React Context.
31 */
32export function SlotProvider({
33 implementations,
34 strict,
35 children,
36}: SlotProviderProps) {
37 return (
38 <SlotContext value={{ implementations, strict: strict ?? false }}>
39 {children}
40 </SlotContext>
41 )
42}