• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
drewmcdonald

drewmcdonald

promptCompare

Public
Like
promptCompare
Home
Code
7
.claude
3
backend
2
docs
1
frontend
4
shared
.mcp.json
deno.json
Environment variables
2
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
.claude
/
skills
/
ai-elements
/
references
/
jsx-preview.md
Code
/
.claude
/
skills
/
ai-elements
/
references
/
jsx-preview.md
Search
…
Viewing readonly version of main branch: v134
View latest version
jsx-preview.md

JSX Preview

A component that dynamically renders JSX strings with streaming support for AI-generated UI.

The JSXPreview component renders JSX strings dynamically, supporting streaming scenarios where JSX may be incomplete. It automatically closes unclosed tags during streaming, making it ideal for displaying AI-generated UI components in real-time.

See scripts/jsx-preview.tsx for this example.

Installation

npx ai-elements@latest add jsx-preview

Features

  • Renders JSX strings dynamically using react-jsx-parser
  • Streaming support with automatic tag completion
  • Custom component injection for rendering your own components
  • Error handling with customizable error display
  • Context-based architecture for flexible composition

Usage with AI SDK

The JSXPreview component integrates with the AI SDK to render generated UI in real-time:

Create val
"use client"; import { JSXPreview, JSXPreviewContent, JSXPreviewError, } from "@/components/ai-elements/jsx-preview"; type GeneratedUIProps = { jsx: string; isStreaming: boolean; }; export const GeneratedUI = ({ jsx, isStreaming }: GeneratedUIProps) => ( <JSXPreview jsx={jsx} isStreaming={isStreaming} onError={(error) => console.error("JSX Parse Error:", error)} > <JSXPreviewContent /> <JSXPreviewError /> </JSXPreview> );

With Custom Components

You can inject custom components to be used within the rendered JSX:

Create val
"use client"; import { JSXPreview, JSXPreviewContent, } from "@/components/ai-elements/jsx-preview"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; const customComponents = { Button, Card, }; export const GeneratedUIWithComponents = ({ jsx }: { jsx: string }) => ( <JSXPreview jsx={jsx} components={customComponents}> <JSXPreviewContent /> </JSXPreview> );

Props

<JSXPreview />

PropTypeDefaultDescription
jsxstringRequiredThe JSX string to render.
isStreamingbooleanfalseWhen true, automatically completes unclosed tags.
componentsRecord<string, React.ComponentType>-Custom components available within the rendered JSX.
bindingsRecord<string, unknown>-Variables and functions available within the JSX scope.
onError(error: Error) => void-Callback fired when a parsing or rendering error occurs.
...propsReact.ComponentProps<-Any other props are spread to the underlying div element.

<JSXPreviewContent />

PropTypeDefaultDescription
renderErrorJsxParserProps[-Custom error renderer passed to react-jsx-parser.
...propsReact.ComponentProps<-Any other props are spread to the underlying div element.

<JSXPreviewError />

PropTypeDefaultDescription
children`ReactNode((error: Error) => ReactNode)`-
...propsReact.ComponentProps<-Any other props are spread to the underlying div element.
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.