$npx @dinachi/cli@latest add streaming-text
Assistant
wordsPerSecondpausedrunKeyanswer.tsx
import { StreamingText } from "@/components/ui/streaming-text"
export function Answer({ text, pending }: { text: string; pending: boolean }) {
return <StreamingText text={text} complete={!pending} />
}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} />;
}Assistant
The clock stops with the reveal, so there is no catch-up burst.
<StreamingText text={text} complete={!pending} paused={paused} />waiting
Assistant
onDone waits for the caller, because catching up is not finishing.
// Catching up to the current chunk and the stream ending are indistinguishable
// from inside the component. Only the caller knows which one happened.
<StreamingText
text={text}
complete={!pending}
onDone={() => setDone(true)}
/>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
runKeyrewinds 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
completeis 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.