Skip to content

Commit db6fab1

Browse files
committed
docs(render): add documentation about withRenderOptions
1 parent 7e6ef4b commit db6fab1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

apps/docs/utilities/render.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,47 @@ Some title
125125
Click me [https://example.com]
126126
```
127127

128+
## 5. Using withRenderOptions
129+
130+
The `withRenderOptions` higher-order function allows your email templates to access render options directly as props. This is useful when you want to customize the email content based on how it's being rendered.
131+
132+
```tsx
133+
import { withRenderOptions } from '@react-email/render';
134+
import { Html, Text } from '@react-email/components';
135+
136+
type MyTemplateProps = { name: string };
137+
138+
export const MyTemplate = withRenderOptions<MyTemplateProps>(({ name, renderOptions }) => {
139+
// Check if rendering as plain text
140+
if (renderOptions?.plainText) {
141+
return `Hello ${name}! This is the plain text version.`;
142+
}
143+
144+
// Default HTML rendering
145+
return (
146+
<Html>
147+
<Text>Hello {name}!</Text>
148+
<Text>This is the HTML version with styling.</Text>
149+
</Html>
150+
);
151+
});
152+
```
153+
154+
Now when you render this component:
155+
156+
```tsx
157+
import { MyTemplate } from './email';
158+
import { render } from '@react-email/render';
159+
160+
// HTML version
161+
const html = await render(<MyTemplate name="John" />);
162+
163+
// Plain text version (component receives renderOptions.plainText = true)
164+
const text = await render(<MyTemplate name="John" />, { plainText: true });
165+
```
166+
167+
The component will automatically receive the render options as the `renderOptions` prop, allowing you to conditionally render different content.
168+
128169
## Options
129170

130171
<ResponseField name="pretty" type="boolean" deprecated>

0 commit comments

Comments
 (0)