HextaUI

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.

Category
AI
Components used
2
Files
4
Usage examples
3
Access
HextaUI Pro (55 blocks)
Source updated
Open in new tab

Part of HextaUI Pro, all 55 blocks, $79 one-time, Compare plans

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.

  1. Get HextaUI Pro

    One payment unlocks every block, including future ones. See pricing.

  2. Add the Pro registry to components.json

    components.json
    {
      "registries": {
        "@hextaui-pro": {
          "url": "https://hextaui.com/r/pro/{name}.json",
          "headers": {
            "Authorization": "Bearer ${HEXTAUI_PRO_TOKEN}"
          }
        }
      }
    }
  3. Add your token

    Create a token on your account page and put it in .env.local as HEXTAUI_PRO_TOKEN.

  4. Add the block

    pnpm dlx shadcn@latest add @hextaui-pro/streaming

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.

"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.

"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.

"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.

PartDescription
StreamingTextA drop-in text element that paces, fades and shows the caret. Use it for plain text replies.
useSmoothTextThe pacing on its own. Returns the text to show right now and whether it is still catching up.

StreamingText

Also accepts every div prop except children.

PropTypeDefault
textEverything received so far. Append to it as chunks arrive.
string–
streamingWhether more text is coming. Shows the caret and keeps the catch-up window open.
booleanfalse
smoothTurn pacing off to render text exactly as received.
booleantrue
charsPerSecondBase reading pace before any catch-up.
number90

useSmoothText(text, options)

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

PropTypeDefault
textThe full text received so far.
string–
options.streamingWhether the source is still sending.
booleanfalse
options.enabledWhen false, the hook returns the text unchanged.
booleantrue
options.charsPerSecondBase reading pace.
number90
  • 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.

Code

4 files, added to components/blocks/streaming.