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 { useStream } from "@hyper-fetch/react"
Parameters
useStream<T>(request: T, options: UseStreamOptionsType)
| Name | Type | Description |
|---|---|---|
| request | | |
| options | |
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;
}
| Name | Type | Description |
|---|---|---|
| chunks | | Raw binary chunks received from the stream. Useful for binary streaming like file downloads. |
| done | | Whether the stream has finished (all chunks consumed). |
| error | | Error from the request or stream consumption. |
| extra | | Response extra metadata (headers, etc.). |
| status | | HTTP status code from the response. |
| streaming | | Whether the stream is currently being consumed. |
| text | | Accumulated text from all stream chunks decoded as UTF-8. Useful for text-based streaming like LLM responses or SSE. |
| abort | | Abort the ongoing stream. |
| reset | | Reset state to initial values, allowing a fresh stream. |
| start | | Start consuming the stream. The request is sent with
|
