Streaming React Components
AI SDK RSC enables you to stream React components from server actions to the client as AI models generate content. This allows you to build responsive, progressively-rendered interfaces.
Core Primitives
createStreamableUI
createStreamableUI creates a streamable UI component that can be updated over time.
Key Methods:
update(node): Replace the current UI node
append(node): Append a new UI node
done(node?): Finalize the stream (required)
error(error): Signal an error
You must always call .done() to finalize the stream, otherwise the UI will remain in a loading state.
createStreamableValue
createStreamableValue creates a streamable primitive value (strings, numbers, objects).
Reading on the Client:
Streaming with streamUI
The streamUI function integrates streaming components with language models.
Text Streaming
Stream text content as React components:
Render components as tools are called:
Generator Functions
Use async generators to stream multiple updates:
Reading Streamable Values
Using Hooks (Client Components)
Without React
Appending vs Updating
update()
Replaces the current UI:
append()
Adds to existing UI:
Error Handling
Handle errors in streaming components:
On the client:
Best Practices
1. Always Call done()
2. Use Async Patterns
3. Handle Errors Gracefully
Common Patterns
Progressive Enhancement
Multi-Step Workflows
Next Steps