# Streaming

> Text that streams from a model at a steady pace. Bursty chunks are smoothed out, with a fade on new words and a caret while it writes.

Canonical: https://hextaui.com/blocks/streaming
Last updated: 2026-10-29

## Overview

Models send text in bursts: a few words, a pause, then a whole sentence at once. Printing each chunk as it lands makes a reply stutter. Streaming keeps what you have received separate from what you show, and reveals it at a steady 90 characters a second.

When chunks pile up, the pace rises to close the gap in about 0.3 seconds, and once the stream ends the rest is flushed in about 0.12 seconds, so the text never trails far behind the model. Emoji and other multi-part characters are never split mid-reveal, and if the text is replaced rather than appended, as after a regenerate, the reveal restarts from what the two versions share.

Text that isn’t streaming renders in full on the first frame, so history and server renders never animate. StreamingText adds a soft fade on the newest words and a caret while it writes. useSmoothText gives you the pacing alone, to put in front of any renderer, including Markdown.

## Installation

### Step 1: Get HextaUI Pro

One payment unlocks every block, including future ones. [See pricing](https://hextaui.com/pricing).

### Step 2: Add the Pro registry to components.json

```json title="components.json"
{
  "registries": {
    "@hextaui-pro": {
      "url": "https://hextaui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${HEXTAUI_PRO_TOKEN}"
      }
    }
  }
}
```

### Step 3: Add your token

Create a token on your [account page](https://hextaui.com/account) and put it in `.env.local` as `HEXTAUI_PRO_TOKEN`.

### Step 4: Add the block

```bash
npx shadcn@latest add @hextaui-pro/streaming
```

## Usage

### With the AI SDK

Render each text part of a useChat message. The part’s own state tells StreamingText when the model is still writing, so finished messages and history appear instantly.

```tsx
"use client"

import * as React from "react"
import { useChat } from "@ai-sdk/react"

import { StreamingText } from "@/components/blocks/streaming/streaming-text"

export function Chat() {
  const { messages, sendMessage, status } = useChat()
  const [input, setInput] = React.useState("")

  return (
    <div className="flex flex-col gap-4">
      {messages.map((message) => (
        <div key={message.id} className="flex flex-col gap-2">
          {message.parts.map((part, index) =>
            part.type === "text" ? (
              <StreamingText
                key={index}
                text={part.text}
                streaming={part.state === "streaming"}
              />
            ) : null
          )}
        </div>
      ))}
      <form
        onSubmit={(event) => {
          event.preventDefault()
          sendMessage({ text: input })
          setInput("")
        }}
      >
        <input
          value={input}
          disabled={status !== "ready"}
          onChange={(event) => setInput(event.target.value)}
        />
      </form>
    </div>
  )
}
```

### With Markdown

Use the hook on its own to smooth the text before any renderer. Streamdown handles unfinished Markdown while it streams; react-markdown works the same way.

```tsx
"use client"

import { Streamdown } from "streamdown"

import { useSmoothText } from "@/components/blocks/streaming/use-smooth-text"

export function MarkdownAnswer({
  text,
  streaming,
}: {
  text: string
  streaming: boolean
}) {
  const smooth = useSmoothText(text, { streaming })

  return (
    <Streamdown mode="streaming" isAnimating={streaming || smooth.animating}>
      {smooth.text}
    </Streamdown>
  )
}
```

### With any stream

Append each chunk to a string and pass it in. This works the same for fetch, OpenAI or Anthropic deltas, or server-sent events.

```tsx
"use client"

import * as React from "react"

import { StreamingText } from "@/components/blocks/streaming/streaming-text"

export function Answer({ prompt }: { prompt: string }) {
  const [text, setText] = React.useState("")
  const [streaming, setStreaming] = React.useState(false)

  const ask = async () => {
    setText("")
    setStreaming(true)
    const response = await fetch("/api/chat", {
      method: "POST",
      body: JSON.stringify({ prompt }),
    })
    const reader = response
      .body!.pipeThrough(new TextDecoderStream())
      .getReader()
    for (;;) {
      const { done, value } = await reader.read()
      if (done) break
      setText((current) => current + value)
    }
    setStreaming(false)
  }

  return (
    <div className="flex flex-col gap-3">
      <button onClick={ask}>Ask</button>
      <StreamingText text={text} streaming={streaming} />
    </div>
  )
}
```

## Anatomy

The parts you compose, from the outside in.

| Part | Description |
| --- | --- |
| `StreamingText` | A drop-in text element that paces, fades and shows the caret. Use it for plain text replies. |
| `useSmoothText` | The pacing on its own. Returns the text to show right now and whether it is still catching up. |

## API reference

### StreamingText

Also accepts every div prop except children.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `text` | `string` | – | Everything received so far. Append to it as chunks arrive. |
| `streaming` | `boolean` | `false` | Whether more text is coming. Shows the caret and keeps the catch-up window open. |
| `smooth` | `boolean` | `true` | Turn pacing off to render text exactly as received. |
| `charsPerSecond` | `number` | `90` | Base reading pace before any catch-up. |

### useSmoothText(text, options)

Returns { text, animating }. animating stays true until the shown text reaches the full text.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `text` | `string` | – | The full text received so far. |
| `options.streaming` | `boolean` | `false` | Whether the source is still sending. |
| `options.enabled` | `boolean` | `true` | When false, the hook returns the text unchanged. |
| `options.charsPerSecond` | `number` | `90` | Base reading pace. |

## Accessibility

- The text container is a polite live region with aria-busy while it streams, so screen readers announce the reply once it settles instead of every character.
- The caret is decorative and hidden from assistive technology.
- With reduced motion, words appear without the fade and the caret stops pulsing. Pacing stays, because it is about reading speed, not motion.

## Built with

The free HextaUI components Streaming is made from. Each one installs on its own.

- [Bubble](https://hextaui.com/docs/bubble) - Chat message bubbles with variants, grouped corners, reactions and room for interactive content.
- [Message](https://hextaui.com/docs/message) - A chat message row with an avatar, name, bubbles and status, where new messages rise in from the sender's side.

## Code

4 files, added to components/blocks/streaming.
