React templates
Render a React Email component to HTML and plain text and send the result.
EmailReact.render turns a React element into the html and text of a message. It needs the React peers and does not use the Email service or any provider SDK.
Example (Rendering a Component and Sending It)
import { } from "effect";
import { } from "@effect-kit/emails";
import * as from "@effect-kit/emails/react";
const = ({ }: { : string }) => <>Hello {}</>;
const = .(function* () {
const = yield* ;
const content = yield* .(< ="Ada" />); return yield* .({
: "hello@example.com",
: "ada@example.com",
: "Welcome",
...,
});
});The component renders once. The plain-text body is derived from that HTML.
Choosing the output
mode selects what render returns, and the success type follows it.
mode | Success type |
|---|---|
"htmlAndText" (default) | { html, text } |
"html" | { html } |
"text" | { text } |
Example (Rendering HTML Only)
import { } from "effect";
import * as from "@effect-kit/emails/react";
const = ({ }: { : string }) => <>Hello {}</>;
const program = .(< ="Ada" />, { : "html" });Errors
render fails with RenderError, whose reason is "InvalidElement", "InvalidOptions" or "InvalidContent". InvalidContent means the output was blank. An exception thrown inside a component is a defect, not a typed error.
Trust
Rendering does not sanitize HTML. Render only templates you wrote, and escape any untrusted value yourself. Interrupting the effect stops waiting for the render but cannot cancel it.