function / @typed/template

renderToHtmlString

Renders a stream of RenderEvents into a single HTML string.

This is a convenience function that collects all events from renderToHtml and joins them into a single string. It is an Effect that resolves when the stream completes.

Package version
1.0.0-beta.13
Category
Buffered HTML
Since
1.0.0

Import

import { renderToHtmlString } from "@typed/template";

Signatures

export declare function renderToHtmlString<const T extends Renderable.Any>(renderable: T): Effect.Effect<string, Renderable.Error<T>, Renderable.Services<T>>;

Why

This is the finite-response convenience over renderToHtml: it preserves ordered chunks but buffers them when the caller needs one complete body.

Ownership and lifetime

The returned Effect runs and finalizes the source Fx. The resulting string is caller-owned; errors and required services remain in the Effect type.

Cost model

Collection requires memory proportional to the complete rendered response. Prefer renderToHtml when the transport can stream chunks.

Examples

import { Effect } from "effect"
import { html } from "@typed/template"
import { renderToHtmlString, HtmlRenderTemplate } from "@typed/template/Html"

const program = Effect.scoped(Effect.gen(function* () {
  const template = html`<div>
    <h1>Hello</h1>
    <p>World</p>
  </div>`

  // Render to single HTML string
  const htmlString = yield* renderToHtmlString(template).pipe(
    Effect.provide(HtmlRenderTemplate)
  )

  console.log(htmlString)
  // "<div><h1>Hello</h1><p>World</p></div>"
}))

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source