Skip to content

StreamProvider

StreamProvider(__namedParameters): Element

Defined in: stream-context.tsx:100

StreamProvider - Context provider for managing multiple streams.

Provides centralized stream state management across components.

StreamProviderProps

Element

import { StreamProvider, useStreamContext } from 'ai.matey.react.stream';
function App() {
return (
<StreamProvider maxStreams={10}>
<ChatComponent />
</StreamProvider>
);
}
function ChatComponent() {
const { startStream, appendToStream, completeStream } = useStreamContext();
const handleNewMessage = async () => {
const streamId = 'message-1';
startStream(streamId);
// ... fetch and stream
for await (const chunk of response) {
appendToStream(streamId, chunk);
}
completeStream(streamId);
};
return <button onClick={handleNewMessage}>Send</button>;
}