renderToReadableStream
Reference
renderToReadableStream(element: JSX.Element, options: Options): ReadableStream<any>
The renderToReadableStream
function is used to render a JSX element to a stream on the server side.
Parameters:
element
: The JSX element to render.options
: Options is an object withrequest
,head
,log
andapplySuspense
, these isOptions
the type:type Options = { request: Request | RequestContext; head?: ComponentType; log?: boolean; applySuspense?: boolean; };
The
request
parameter is mandatory here. Meanwhile thehead
,log
andapplySuspense
are optional. The default value forlog
istrue
. The default value forapplySuspense
istrue
becauserenderToReadableStream
is used for streaming and we need to apply suspense to avoid blocking the chunks.
Returns:
- A
Promise
that resolves to a string representing the rendered JSX element.
Example usage:
import { renderToReadableStream } from "brisa";
const stream = renderToReadableStream(<div>Hello, world!</div>, {
request: new Request("http://localhost"),
});
console.log(await Bun.readableStreamToText(stream)); // Output: '<div>Hello, world!</div>'
In principle you should never use it inside Brisa Framework.