Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

ClientSlot.tsx

34 lines733 Bytes

1'use client'
2​
3import { useSlotContext } from './SlotContext'
4​
5export interface ClientSlotProps {
6 slot: string
7 args: Array<unknown>
8}
9​
10export function ClientSlot({ slot, args }: ClientSlotProps) {
11 const ctx = useSlotContext()
12​
13 if (!ctx) {
14 throw new Error('ClientSlot must be rendered within SlotProvider')
15 }
16​
17 const impl = ctx.implementations[slot]
18​
19 // No implementation provided
20 if (impl === undefined) {
21 if (ctx.strict) {
22 throw new Error(`Missing slot implementation for "${slot}"`)
23 }
24 return null
25 }
26​
27 // For children slot or any non-function value, render directly
28 if (typeof impl !== 'function') {
29 return <>{impl}</>
30 }
31​
32 // Render function with args
33 return <>{impl(...args)}</>