content/docs/07-reference/03-ai-sdk-rsc/05-read-streamable-value.mdx
readStreamableValueIt is a function that helps you read the streamable value from the client that was originally created using createStreamableValue on the server.
<Snippet
text={import { readStreamableValue } from "@ai-sdk/rsc"}
prompt={false}
/>
async function generate() {
'use server';
const streamable = createStreamableValue('');
streamable.append('Hello');
streamable.append(' ');
streamable.append('World');
streamable.done();
return streamable.value;
}
import { readStreamableValue } from '@ai-sdk/rsc';
export default function Page() {
const [generation, setGeneration] = useState('');
return (
<div>
<button
onClick={async () => {
const stream = await generate();
for await (const value of readStreamableValue(stream)) {
setGeneration(value);
}
}}
>
Generate
</button>
</div>
);
}
<PropertiesTable content={[ { name: 'stream', type: 'StreamableValue', description: 'The streamable value to read from.', }, ]} />
It returns an async iterator that contains the values emitted by the streamable value.