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#

Shell
npm install @orshot/embed-react
# or
pnpm add @orshot/embed-react
# or
yarn add @orshot/embed-react

Usage#

Import the OrshotEmbed component and render it in your application.

TypeScript
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:

PropTypeDescription
embedIdstringYour Embed configuration ID.
templateIdstring | numberID of the template to load initially.
modificationsobjectLayer values to set. Uses embed control, see below.
widthstring | numberWidth of the iframe (default: 100%).
heightstring | numberHeight of the iframe (default: 100%).
classNamestringClass name for the container.
styleobjectInline styles for the container.
urlstringBase embed URL. Default https://orshot.com/embeds.

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:

  • onTemplateCreate
  • onTemplateUpdate
  • onTemplateContent
  • onDownloadPng
  • onDownloadPdf
  • onDownloadHtml
  • onError

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:

TypeScript
// 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#

View on GitHub

Was this page helpful?

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