The widget in a React component
Single-page apps built with Vite, Create React App or similar, where routes render in the browser.
- In VideoTestimonials, open Studio → Widgets, open (or create) a widget, and copy the code from its Code tab (HTML / Script) — the code is a <div> with data-vt-* attributes and one <script> tag.
- Create a component that renders the <div> with the same data-vt-* attributes.
- In a useEffect, create a script element pointing at https://videotestimonials.video/embed.js and append it to the page, so it runs after the div has mounted.
- Remove the script element in the effect's cleanup function.
- Render the component wherever the testimonials should appear.
import { useEffect } from "react";
export function Testimonials() {
useEffect(() => {
const script = document.createElement("script");
script.src = "https://videotestimonials.video/embed.js";
script.async = true;
document.body.appendChild(script);
return () => script.remove();
}, []);
// Copy these attributes from your widget's Code tab.
return <div data-vt-widget="carousel" data-vt-space-id="YOUR_SPACE_ID" />;
}embed.js finds widget divs once, when it runs. Loading it once in index.html only works if the div is already in the page at that moment.
Source: React docs: useEffect (connecting to an external system)

