Orshot Logo
OrshotDocs
Orshot Embed

React SDK

Integrate Orshot Embed into your React applications

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-react

Usage

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"
        modifications={{
          name: "John Doe",
          role: "Software Engineer",
        }}
        onTemplateCreate={(data) => console.log("Created:", data)}
        onError={(err) => console.error("Error:", err)}
      />
    </div>
  );
}

Props

The component accepts all standard configuration options plus event handlers:

PropTypeDescription
embedIdstringYour Embed configuration ID.
templateIdstring | numberID of the template to load initially.
modificationsobjectInitial data to populate the template.
widthstring | numberWidth of the iframe (default: 100%).
heightstring | numberHeight of the iframe (default: 100%).
classNamestringClass name for the container.
urlstringOptional custom URL for self-hosting.

Events

Event handlers follow the on[EventName] naming convention:

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

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
embedRef.current.requestContent("png", { scale: 2 });

Source

View on GitHub

On this page