React SDK
Drop the OrshotEmbed component into a React app and configure it with props.
Updated
The React SDK provides a convenient wrapper component around the core Orshot Embed library, making it easy to integrate image generation capabilities into your React applications.
Installation#
npm install @orshot/embed-react
# or
pnpm add @orshot/embed-react
# or
yarn add @orshot/embed-reactUsage#
Import the OrshotEmbed component and render it in your application.
import { OrshotEmbed } from "@orshot/embed-react";
import { useRef } from "react";
function App() {
const embedRef = useRef();
return (
<div style={{ height: "700px" }}>
<OrshotEmbed
ref={embedRef}
embedId="YOUR_EMBED_ID"
templateId="TEMPLATE_ID"
onTemplateCreate={(data) => console.log("Created:", data)}
onTemplateUpdate={(data) => console.log("Updated:", data)}
/>
</div>
);
}Props#
The component accepts these props plus event handlers:
| Prop | Type | Description |
|---|---|---|
embedId | string | Your Embed configuration ID. |
templateId | string | number | ID of the template to load initially. |
modifications | object | Layer values to set. Uses embed control, see below. |
width | string | number | Width of the iframe (default: 100%). |
height | string | number | Height of the iframe (default: 100%). |
className | string | Class name for the container. |
style | object | Inline styles for the container. |
url | string | Base embed URL. Default https://orshot.com/embeds. |
modifications, setTemplate and setModifications use embed
control, which needs Enable
Events and a Scale plan. On other plans the embed ignores them. The
templateId prop still opens the template, because it is also set on the
iframe URL.
The SDK does not pass userId, token, lang, theme or other URL parameters yet. For per-user data or JWT authentication, use a plain iframe.
Events#
Event handlers follow the on[EventName] naming convention:
onTemplateCreateonTemplateUpdateonTemplateContentonDownloadPngonDownloadPdfonDownloadHtmlonError
Each handler receives the event's data object. onError does not receive the error message yet, because errors carry it outside data. To read errors, and events the SDK does not map (such as orshot:embed:ready, AVIF and MP4 downloads), listen with window.addEventListener("message", ...). See the Events documentation for payload details.
Methods#
By using a ref, you can access imperative methods to control the embed programmatically:
// Change template
embedRef.current.setTemplate("new-template-id");
// Update data
embedRef.current.setModifications({ title: "New Title" });
// Request export. The result arrives in onTemplateContent
embedRef.current.requestContent("png", { scale: 2 });
// Send any other message to the embed
embedRef.current.send("orshot:embed:control", { pageIndex: 2 });requestContent returns nothing. The content arrives in onTemplateContent. It takes png, pdf or html, and needs Allow Template Download turned on.
The package also exports a useOrshotEmbed(options) hook. It returns containerRef (attach it to a div), setTemplate, setModifications, requestContent and send.
Source#
Ready to automate?
Start rendering images, PDFs and videos from your templates in under 2 minutes. Free plan, no credit card.
Get your API key- Image, PDF and video generation via API
- Visual editor with AI and smart layouts
- Zapier, Make, MCP and 40+ integrations
- White-label embed for your own app
- 100 free credits a month, no credit card required