useXDSStreamingText@xds/core · hooks

Usage

Smooths bursty streamed text into a steady character-by-character reveal using requestAnimationFrame. Decouples arrival rate from display rate. Advances on word and syntax boundaries to avoid slicing mid-markdown or mid-word, preventing visual glitches with markdown renderers. Animation timing derives from XDS motion tokens via useXDSTheme when available, with sensible fallbacks outside a theme provider. Snaps to full text when isStreaming becomes false.

Best practices

GuidancePractices
DoPass the accumulated text (not individual chunks) as targetText — the hook handles incremental reveal internally.
DoSet isStreaming to false when the stream completes to snap to the final text.
DoUse speed='instant' for non-animated contexts like search results or when reduced motion is preferred.
Don'tUse for static text that does not change — the hook adds unnecessary overhead for non-streaming content.

Parameters

ParamTypeDescription
targetTextrequired
stringThe full target text to reveal. As new chunks arrive, update this value with the accumulated text.
isStreamingrequired
booleanWhether text is currently being streamed. When false, the hook returns the full targetText immediately.
options
UseStreamingTextOptionsOptional configuration for streaming behavior.
options.speed
'natural' | 'fast' | 'instant' (default: 'natural')Speed preset for text reveal. 'natural' is steady ~2 chars/frame, 'fast' scales with backlog ~4 chars/frame, 'instant' returns full text with no animation.

Returns

FieldTypeDescription
displayedTextstringThe portion of targetText to render. Grows steadily toward the full targetText during streaming, or equals targetText when not streaming.

Import

ts
import {useXDSStreamingText} from '@xds/core/hooks'