Streaming Text

A component that displays text character by character with programmatic control over streaming state (idle, streaming, paused, completed).

Installation

Install the following dependencies:

Loading...

bash

API Reference

Props list

PropTypeDefaultExampleDescription
textstring-Hello, world!The text to be streamed character by character.
delaynumber1050The delay in milliseconds between each character.
indicatorReactNode-<StreamingTextIndicator />Optional indicator to show while streaming (e.g., a blinking cursor). Only displayed when streaming is in progress.
autoStartbooleanfalsetrueWhether to automatically start streaming on mount.
onStateChange(state: StreamingState) => void-(state) => console.log(state)Callback fired when streaming state changes. Use this to handle state transitions (idle → streaming → paused → completed).
classNamestring-custom-classAdditional CSS classes to apply to the component.

Programmatic Controls

The component exposes control methods via a ref:

MethodDescription
start()Start or resume streaming. If already completed, resets to idle and starts streaming.
pause()Pause streaming (can be resumed later with start()).
reset()Reset streaming to the beginning (idle state).
getState()Get the current streaming state. Returns one of: "idle", "streaming", "paused", or "completed".

Loading...

tsx

Streaming States

The component manages four distinct states:

StateDescription
"idle"Initial state. Streaming has not started yet.
"streaming"Actively streaming text character by character.
"paused"Streaming is paused. Can be resumed with start().
"completed"All characters have been streamed. Can be reset with reset() or restarted with start().

Streaming Indicator

Use the StreamingTextIndicator component to show a visual indicator while streaming:

Loading...

tsx