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