{post.title}
{post.body}
// Composite Component patterns:
// - children slot for free-form composition
// - render-prop slot when the server must pass data into client UI
// - component prop slot for reusable typed interactive controls
import type { ComponentType, ReactNode } from 'react'
import { createFileRoute } from '@tanstack/react-router'
import { createServerFn } from '@tanstack/react-start'
import {
CompositeComponent,
createCompositeComponent,
} from '@tanstack/react-start/rsc'
import { z } from 'zod'
// Replace with your own server-only data layer
declare const db: {
posts: {
findById(postId: string): Promise<{
id: string
authorId: string
title: string
body: string
}>
}
products: {
findById(productId: string): Promise<{
id: string
name: string
price: number
}>
}
}
const getPostCard = createServerFn({ method: 'GET' })
.inputValidator(z.object({ postId: z.string() }))
.handler(async ({ data }) => {
const post = await db.posts.findById(data.postId)
const src = await createCompositeComponent<{
children?: ReactNode
renderActions?: (args: { postId: string; authorId: string }) => ReactNode
}>((props) => (
{post.body}{post.title}