Skip to main content
Version: v8.0.0

useStream

Hook for consuming streaming responses chunk-by-chunk. Works with any request that uses the fetch adapter's streaming: true option.

Provides both accumulated text (for LLM/SSE use cases) and raw chunks

(for binary streaming / file downloads).


Import
import { useStream } from "@hyper-fetch/react"

Parameters

useStream<T>(request: T, options: UseStreamOptionsType)
Parameters
NameTypeDescription
request
T
options
UseStreamOptionsType

Returns

type UseStreamReturnType<T> = {
abort: () => void;
chunks: Uint8Array[];
done: boolean;
error: ExtractErrorType<T> | null;
extra: ExtractAdapterExtraType<ExtractAdapterType<T>> | null;
reset: () => void;
start: () => void;
status: number | null;
streaming: boolean;
text: string;
}
useStream
NameTypeDescription
chunks
Uint8Array[]

Raw binary chunks received from the stream. Useful for binary streaming like file downloads.

done
boolean

Whether the stream has finished (all chunks consumed).

error
ExtractErrorType<T> | null

Error from the request or stream consumption.

extra
ExtractAdapterExtraType<ExtractAdapterType<T>> | null

Response extra metadata (headers, etc.).

status
number | null

HTTP status code from the response.

streaming
boolean

Whether the stream is currently being consumed.

text
string

Accumulated text from all stream chunks decoded as UTF-8. Useful for text-based streaming like LLM responses or SSE.

abort
() => void

Abort the ongoing stream.

reset
() => void

Reset state to initial values, allowing a fresh stream.

start
() => void

Start consuming the stream. The request is sent with streaming: true .