@inkdes-email/get-html
v0.2.1
Published
A React email helper to get the HTML of a React email component (InkDes Mailer)
Maintainers
Readme
@inkdes-email/get-html
Helper function to convert Email components to text only.
Installation
# pnpm
pnpm add @inkdes-email/get-html
# npm
npm install @inkdes-email/get-html
# yarn
yarn add @inkdes-email/get-html- Signature:
(EmailTemplate: any) => {html: string | null, error: Error | null} - Description: Renders a valid React element to a static HTML string using
renderToStaticMarkup. Returns{ html, error: null }on success or{ html: null, error }on failure. Validates input withReact.isValidElement. - Example:
import { getHtml } from "@inkdes-email/get-html";
import { Html, Head, Body, Text, Button } from "@inkdes-emailcomponents";
function EmailTemplate() {
return (<Html>
<Body>
<Text>Hello</Text>
<Button text='Button' url='#' />
</Body>
</Html>)
}
const { html, error } = getHtml(<EmailTemplate />);
if (error) {
// handle error
} else if (html) {
// use html
}- Requirements:
- Node >= 18
- React 18 or 19
