| 1 | # `react-markup` |
| 2 | |
| 3 | This package provides the ability to render standalone HTML from Server Components for use in embedded contexts such as e-mails and RSS/Atom feeds. It cannot use Client Components and does not hydrate. It is intended to be paired with the generic React package, which is shipped as `react` to npm. |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```sh |
| 8 | npm install react react-markup |
| 9 | ``` |
| 10 | |
| 11 | ## Usage |
| 12 | |
| 13 | ```js |
| 14 | import { experimental_renderToHTML as renderToHTML } from 'react-markup'; |
| 15 | import EmailTemplate from './my-email-template-component.js' |
| 16 | |
| 17 | async function action(email, name) { |
| 18 | "use server"; |
| 19 | // ... in your server, e.g. a Server Action... |
| 20 | const htmlString = await renderToHTML(<EmailTemplate name={name} />); |
| 21 | // ... send e-mail using some e-mail provider |
| 22 | await sendEmail({ to: email, contentType: 'text/html', body: htmlString }); |
| 23 | } |
| 24 | ``` |
| 25 | |
| 26 | Note that this is an async function that needs to be awaited - unlike the legacy `renderToString` in `react-dom`. |
| 27 | |
| 28 | ## API |
| 29 | |
| 30 | ### `react-markup` |
| 31 | |
| 32 | See https://react.dev/reference/react-markup |
| 33 | |
| 34 | ## Thanks |
| 35 | |
| 36 | The React team thanks [Nikolai Mavrenkov](https://www.koluch.ru/) for donating the `react-markup` package name. |