useStream
useStream(
options):UseStreamReturn
Defined in: react-hooks/src/use-stream.ts:79
useStream - React hook for generic text streaming.
Provides state management for streaming text from various sources including fetch responses, ReadableStreams, and async iterables.
Parameters
Section titled “Parameters”options
Section titled “options”UseStreamOptions = {}
Returns
Section titled “Returns”Example
Section titled “Example”import { useStream } from 'ai.matey.react.hooks';
function StreamingComponent() { const { text, isStreaming, startStream, stop } = useStream({ onComplete: (fullText) => console.log('Completed:', fullText), });
const handleClick = async () => { const response = await fetch('/api/stream'); await startStream(response); };
return ( <div> <button onClick={handleClick} disabled={isStreaming}>Start</button> <button onClick={stop} disabled={!isStreaming}>Stop</button> <pre>{text}</pre> </div> );}