Web DevelopmentInfusible Coder Guides

Generative UI: How to Stream Dynamic React Components Directly from AI Models

Syed Usama Ahmad3 min read542 words
Generative UI system assembling responsive interface components from a user's intent

Written by

Syed Usama Ahmad

CEO & Co-Founder, Infusible Coder Pvt Ltd

Reviewed by

Infusible Coder Editorial Team

Updated 15 August 2026

For years, conversational AI was trapped inside a single primitive: the text bubble. If you asked an AI to help compare four mortgage plans, it dumped ten paragraphs of text and an unformatted markdown table. Generative UI breaks this barrier by rendering interactive, rich React components in real time.

When software combines conversational intelligence with direct manipulation interfaces (sliders, clickable date pickers, real-time charts), task completion times drop by over 60%. In this tutorial, we demonstrate how Generative UI works in React.

The Architecture of Generative UI

Generative UI relies on a seamless client-server contract:

  1. User Prompt: The user types: "Show me available flights from Islamabad to Dubai next Tuesday under $400."
  2. Model Tool Calling: The LLM decides that text is inadequate and invokes a registered tool: render_flight_selector(flights=[...]).
  3. Streaming Protocol: The backend streams tool call arguments as chunked JSON over HTTP or WebSockets.
  4. Dynamic Component Mounting: The frontend component registry intercepts the tool name and mounts the pre-compiled <FlightSelector flights={data} /> component inside the chat timeline.
  5. Bidirectional Interaction: The user selects a flight seat on the interactive card, which dispatches a payload back to the conversation thread.

Building a Generative UI Component Registry

Here is a clean, production-ready React implementation pattern:

// FlightPickerWidget.jsx - Interactive React Component
import React, { useState } from 'react';

export function FlightPickerWidget({ flights, onSelectFlight }) {
  const [selectedId, setSelectedId] = useState(null);

  return (
    <div className="bg-zinc-900 border border-[#86c32a]/40 rounded-2xl p-5 my-4 shadow-xl">
      <h3 className="text-lg font-bold text-white mb-3">Available Flights</h3>
      <div className="space-y-3">
        {flights.map((flight) => {
          const isSelected = selectedId === flight.id;
          const cardClass = isSelected
            ? 'p-4 rounded-xl border cursor-pointer transition-all border-[#86c32a] bg-[#86c32a]/10'
            : 'p-4 rounded-xl border cursor-pointer transition-all border-zinc-800 bg-zinc-800/50 hover:border-zinc-700';

          return (
            <div
              key={flight.id}
              onClick={() => {
                setSelectedId(flight.id);
                onSelectFlight(flight);
              }}
              className={cardClass}
            >
              <div className="flex justify-between items-center">
                <div>
                  <p className="font-semibold text-white">{flight.airline} • {flight.flightNumber}</p>
                  <p className="text-sm text-zinc-400">{flight.departureTime} → {flight.arrivalTime}</p>
                </div>
                <p className="text-lg font-bold text-[#a0e933]">USD {flight.priceUSD}</p>
              </div>
            </div>
          );
        })}
      </div>
    </div>
  );
}

Registering Tools with the LLM API

We inform the model of our UI capability via standard JSON Schema tool definitions:

{
  "name": "render_flight_picker",
  "description": "Render an interactive flight selection widget when the user asks for flight schedules or pricing.",
  "parameters": {
    "type": "object",
    "properties": {
      "flights": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": { "type": "string" },
            "airline": { "type": "string" },
            "flightNumber": { "type": "string" },
            "departureTime": { "type": "string" },
            "arrivalTime": { "type": "string" },
            "priceUSD": { "type": "number" }
          },
          "required": ["id", "airline", "flightNumber", "departureTime", "arrivalTime", "priceUSD"]
        }
      }
    },
    "required": ["flights"]
  }
}

Best Practices for Generative UI in Production

  • Graceful Skeleton States: While JSON arguments are streaming over the network, display a skeleton placeholder matching the component's final dimensions to prevent layout shifts.
  • Strict Error Boundaries: Wrap every dynamic component in a React Error Boundary. If the model outputs malformed JSON, gracefully fall back to formatted text.
  • Accessibility & Keyboard Navigation: Ensure all generated interactive widgets support full ARIA labels, focus management, and keyboard navigation.

Elevating User Experiences with Infusible Coder

Modern web users expect dynamic, delightful interfaces. Our full-stack engineering team specializes in modern React, Vite, and Next.js architectures integrated with cutting-edge AI streaming protocols. Check out our web development services or see our work in our portfolio.

Frequently asked questions

What is Generative UI?

Generative UI is an interface pattern where an AI model streams structured component arguments that dynamically mount real, interactive React components (buttons, sliders, graphs, forms) in the user interface, instead of outputting plain text or static markdown tables.

Does Generative UI generate raw JavaScript code on the fly in the browser?

No. Generating and running uncompiled JavaScript via eval() is insecure. Instead, developers build a library of pre-compiled React components (e.g. FlightCard, PricingSlider, ExpenseChart), and the LLM calls a tool that passes structured JSON props to instantiate those components safely.

Can users interact with Generative UI components and send data back to the AI?

Yes. Generative UI components are full React components with local state. When a user clicks a button, adjusts a slider, or submits a form inside a generated widget, the component can trigger an event that sends context back to the AI conversation stream.

Which libraries support Generative UI in React?

The Vercel AI SDK (with React Server Components / Client hooks), custom JSON Schema tool listeners, and LangChain UI frameworks all support streaming Generative UI.

Put this AI approach to work

Infusible Coder designs production AI and software systems for businesses, and teaches practical AI skills through our training programs in Kohat and online.