Sequel and Hubspot embed code in React

Load Scripts Dynamically

// hooks/useExternalScript.ts
import { useEffect } from "react";

export function useExternalScript(src: string, type = "text/javascript", module = false) {
  useEffect(() => {
    const script = document.createElement("script");
    script.src = src;
    script.async = true;
    script.type = module ? "module" : type;

    document.body.appendChild(script);
    return () => {
      document.body.removeChild(script);
    };
  }, [src, type, module]);
}

Embed Component

// components/SequelHubSpotEmbed.tsx
import { useEffect } from "react";
import { useExternalScript } from "@/hooks/useExternalScript";

interface Props {
  sequelEventId: string;
}

export default function SequelHubSpotEmbed({ sequelEventId, hubspotFormOptions }: Props) {
  useExternalScript("https://prod-assets.sequelvideo.com/uploads/toolkit/sequel.js", "module", true);
  useExternalScript("https://js.hsforms.net/forms/v2.js");

  useEffect(() => {
    // Wait for both scripts to load
    const interval = setInterval(() => {
      if (window.hbspt && window.Sequel) {
        // Load Sequel
        window.Sequel.renderSequelWithHubspotFrame({
          sequelEventId,
        });

        clearInterval(interval);
      }
    }, 100);

    return () => clearInterval(interval);
  }, [sequelEventId]);

  return (
    <>
      <div id="hubspotForm" />
      <div id="sequel_root" />
    </>
  );
}

Usage Example

<SequelHubSpotEmbed
  sequelEventId="d05a39c9-b5ba-4f4b-bd1d-58c3440ead91"
/>

🧠 Notes

  • useExternalScript: Ensures scripts are loaded dynamically in React. Avoids SSR issues in frameworks like Next.js.
  • window.Sequel and window.hbspt: Make sure these libraries are fully loaded before calling their methods.
  • Sequel removes the form container #hubspotForm after successful registration.