Streaming Response

An AI reply that develops into focus word by word, with markdown, a quiet caret, and a reply bar.

Dependencies

motionlucide-react

Interaction Type

Press Replay to watch the answer arrive. Words arrive in small uneven bursts like a real model, pausing briefly at commas and full stops, and each burst sharpens out of a soft blur behind a small dot that glides along the line. Bold, code, lists, and links are formatted the moment they appear, never as raw symbols. Press Stop to cut it off. Once it finishes, copy it, retry it, or rate it.

Props

Options you can pass to customize this component.

Prop
Type
Description
text*
string

Everything received so far. Pass the growing string as it streams; markdown is supported.

status
streamingdonestopped

Streaming reveals text as it arrives. Done finishes revealing what is left. Stopped freezes on what was shown.

speed
number

Average words per second once caught up. It speeds up while behind, so bursts never pile up.

ink
string

An optional color new words land in before they settle to the text color, also used for the dot. Unset, everything stays monochrome.

actions
boolean

Shows copy and rating buttons once the reply settles.

onRetry
() => void

Adds a retry button that calls this.

onFeedback
(feedback: "up" | "down" | null) => void

Called when a thumb is pressed, with null when it is pressed again to clear it.

defaultFeedback
"up""down"null

The rating to show on first render, like one saved earlier.

onCopy
(text: string) => void

Called with the copied text. After a stop, only the part that was shown is copied.

className
string

Extra classes merged onto the root element (data-slot="streaming-response", with data-status). Font and color come from the parent.

Installation

npx shadcn@latest add swamimalode07/rare-ui/streaming-response

How to use

"use client"
import { StreamingResponse } from "@/components/ui/streaming-response"
export function Reply({ text, done, onRetry }: { text: string; done: boolean; onRetry: () => void }) {
return (
<StreamingResponse
// text grows as tokens arrive, like useChat's message content
text={text}
status={done ? "done" : "streaming"}
onRetry={onRetry}
onFeedback={(rating) => console.log(rating)}
/>
)
}

Source Code

Click the code icon in the top-right corner to view the source code.

Keep in mind

Most components here are recreations of great work from around the web. I don't claim to be the original creator - this is my attempt to reverse-engineer, replicate, and often add a few extra features. I've tried to credit everyone; if I missed someone, let me know.

Contact

Found a bug or issue? Feel free to drop a DM.

License & Usage

  • •MIT with the Commons Clause and an attribution requirement. Free to use, modify and ship in personal and commercial projects, closed source included. You own the code once it is in your project.
  • •Credit is required. Any project shipping a Rare UI component must credit Rare UI with a visible link back to rareui.com, in a footer, an about page, a credits screen or a README.
  • •Don't strip the credit or the copyright notice from the source you copied.
  • •Don't sell, sublicense or redistribute the components themselves, on their own, bundled into a template, kit, theme or paid course, or ported to another framework.
  • •Don't republish them. No mirrors, no re-uploads, no listing them as your own work.
  • •Don't repackage the registry as a competing component library.
  • •Don't claim authorship of a component or of Rare UI itself.
  • •The LICENSE file in the repository is the full text and governs. Ask first if your use doesn't fit these rules.
Streaming Response

Why do springs feel better than easing curves?

Thinking