Staaarter

AI Streaming Response with Live Typing

A bounded chat panel showing one user prompt and one AI response. The response briefly shows a skeleton loading placeholder, then reveals word by word with a blinking cursor to simulate a live streaming model response. A "Stop generating" button halts the animation early, matching the stop control found in real AI chat products.

By Staaarter Team
Chat
Docs
Live preview

Docs

Installation

A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its button dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/ai-streaming-response-typewriter.json

Prefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/chat/chat5.tsx instead.

Usage

The file also exports chat5Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.

import { Chat5, chat5Demo } from "@/components/blocks/chat/chat5";

export default function Page() {
  return <Chat5 {...chat5Demo} />;
}

Props

PropTypeDefaultDescription
headingstring"Assistant"Small heading shown in the panel header.
userPromptstringnoneThe user's chat message, shown as a static bubble above the response.
responsestringnoneFull AI response text that gets revealed word-by-word by the typewriter effect.
classNamestringnoneExtra classes for the outer panel element.

Behavior notes

  • Real client state: a skeleton loading placeholder shows for ~700ms (useState isLoading, starts true for a deterministic SSR-safe render), then a setInterval reveals the response word-by-word into a `typed` string.
  • The blinking cursor after the in-progress text is a static `|` character using CSS `animate-pulse`, not a custom keyframe.
  • The "Stop generating" button is fully functional: clicking it clears the interval early and freezes the response at whatever text had been revealed so far, then shows a "Generation stopped" note.
  • No timestamps or durations are computed from Date.now(); the loading delay and typing speed are fixed literal millisecond intervals.