Render in React
Draw the answer as it streams — prose a word at a time, each component in the place the model put it.
Install
Section titled “Install”npm install ./vendor/val-genui/val-genui-protocol-2.0.0.tgz ./vendor/val-genui/val-genui-react-1.0.0.tgzDraw a reply
Section titled “Draw a reply”import { GenUiReplyView, genUiHeaders } from '@val-genui/react'import '@val-genui/react/styles.css'
export function Answer({ question }: { question: string }) { // Once per question — in a handler or a memo, not on every render. const source = useMemo( () => fetch('/api/chat', { method: 'POST', headers: genUiHeaders(), body: question }), [question], ) return <GenUiReplyView source={source} onAction={(action) => send(action)} />}source takes a fetch(…) or its Response, a ReadableStream, or an async iterable (a WebSocket, a framework’s data stream). Or pass reply for a stored answer.
Handle actions
Section titled “Handle actions”Live — press a button to see the action your app receives
onAction receives { partId, component: { slug, version }, action, payload }. Send it to your backend, where genui.actionMessage(action) turns it into a message for your agent.
Your own layout
Section titled “Your own layout”const { reply, status, error } = useGenUiReply(source)reply.parts.map((part) => <GenUiPart key={part.id} part={part} onAction={send} />)One component, no model
Section titled “One component, no model”import { RenderWidget } from '@val-genui/react'
<RenderWidget xml={component.xml} data={component.data} theme={component.theme} brightness="dark" />Markup, data and theme in; elements out. It fetches nothing.
Theme and dark mode: see Theming.