Streaming Text

Animated

Reveals a streamed answer a word at a time.

Source
$npx @dinachi/cli@latest add streaming-text
Assistant

wordsPerSecond
paused
runKey

Usage

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

export function Answer({ text, pending }: { text: string; pending: boolean }) {
  return <StreamingText text={text} complete={!pending} />
}

Examples

Assistant

Words arriving as the stream delivers them.
import { StreamingText } from '@/components/ui/streaming-text';

export function Example() {
  const [text, setText] = React.useState("");
  const [pending, setPending] = React.useState(true);

  return <StreamingText text={text} complete={!pending} />;
}

Notes

Motion tier

Needs motion. add --all skips it; install with add --motion or by name.

Signalling the end

The component cannot tell a pause between chunks from the end of the stream. Pass complete while streaming:

<StreamingText text={text} complete={!pending} />

Leave it at the default true for a string that is already whole.

Behaviour

  • Paced by elapsed time, so a dropped frame does not put it out of sync.
  • Reveals whole words, fading opacity and blur in place; later text does not move.
  • Progress only moves forward. Appended text extends the reveal; only runKey rewinds it.

When to use it

  • A single answer arriving over a network, a token at a time.
  • Skip it for a string already complete, or for page body copy.

API

textstring
The text so far. Required. Appended text resumes the reveal.
completeboolean = true
Whether the stream has ended. Drives the caret, onDone and the announcement.
runKeynumber = 0
Change it to rewind to the first word.
pausedboolean = false
Holds the reveal. The clock stops too, so resuming does not burst.
wordsPerSecondnumber = 14
Reveal pace. Can change mid-stream without restarting.
onDone() => void
Fires once the reveal catches up and complete is true.

Accessibility

  • The visible paragraph is aria-hidden.
  • The full text is announced once, politely, when the reveal catches up and complete is true.
  • Reduced motion keeps the word-by-word reveal and drops the blur.
  • The caret is solid while streaming and blinks once done; never under reduced motion.