export const metadata = { title: "Quick Start" } # Quick Start Get up and running with json-render in 5 minutes. ## 1. Define your catalog Create a catalog that defines what components AI can use: ```typescript // lib/catalog.ts import { defineCatalog } from '@json-render/core'; import { schema } from '@json-render/react'; import { z } from 'zod'; export const catalog = defineCatalog(schema, { components: { Card: { props: z.object({ title: z.string(), description: z.string().nullable(), }), slots: ["default"], description: "Container card with optional title", }, Button: { props: z.object({ label: z.string(), action: z.string().nullable(), }), description: "Clickable button that triggers an action", }, Text: { props: z.object({ content: z.string(), }), description: "Text paragraph", }, }, actions: { submit: { params: z.object({ formId: z.string() }), description: "Submit a form", }, navigate: { params: z.object({ url: z.string() }), description: "Navigate to a URL", }, }, }); ``` ## 2. Define your components Use `defineRegistry` to map catalog types to React components. Each component receives type-safe `props`, `children`, and `emit`: ```tsx // lib/registry.tsx import { defineRegistry } from '@json-render/react'; import { catalog } from './catalog'; export const { registry } = defineRegistry(catalog, { components: { Card: ({ props, children }) => (

{props.title}

{props.description && (

{props.description}

)} {children}
), Button: ({ props, emit }) => ( ), Text: ({ props }) => (

{props.content}

), }, }); ``` ## 3. Create an API route Set up a streaming API route for AI generation: ```typescript // app/api/generate/route.ts import { streamText } from 'ai'; import { catalog } from '@/lib/catalog'; export async function POST(req: Request) { const { prompt } = await req.json(); // Generate system prompt from catalog const systemPrompt = catalog.prompt(); const result = streamText({ model: 'anthropic/claude-haiku-4.5', system: systemPrompt, prompt, }); return result.toTextStreamResponse(); } ``` ## 4. Render the UI Use providers and the `Renderer` with your registry to display AI-generated UI: ```tsx // app/page.tsx 'use client'; import { Renderer, StateProvider, ActionProvider, VisibilityProvider, ValidationProvider, useUIStream } from '@json-render/react'; import { registry } from '@/lib/registry'; export default function Page() { const { spec, isStreaming, send } = useUIStream({ api: '/api/generate', }); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); const formData = new FormData(e.currentTarget); send(formData.get('prompt') as string); }; return ( console.log('Submit:', params), navigate: (params) => console.log('Navigate:', params), }}>
); } ``` ## Next steps - Learn about [catalogs](/docs/catalog) in depth - Explore [data binding](/docs/data-binding) for dynamic values - Add [action handlers](/docs/registry#action-handlers) for interactivity - Implement [conditional visibility](/docs/visibility)