# Add testimonials to a React app

> Collect and show customer testimonials in a React app (Vite, Create React App or any single-page app) with SiteBackend - one script tag and a small component.

Source: https://sitebackend.com/docs/testimonials/react · Updated: 2026-11-19

Add SiteBackend testimonials to a React app with a placeholder `div` and one script. This works for any single-page app built with Vite, Create React App, React Router or TanStack Router. For Next.js, see [the Next.js guide](https://sitebackend.com/docs/testimonials/nextjs).

Get the IDs from your site's **Testimonials** tab in the dashboard: **Collect** for the form customers fill in (`c_…`), and **Widgets** for the wall, carousel, highlight or badge that shows approved ones (`w_…`).

## Load the script once

Add the script to `index.html`, so every page of the app can use widgets:

```html title="index.html"
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.tsx"></script>
  <script src="https://sitebackend.com/widget.js" async></script>
</body>
```

## Add a component

```tsx title="src/components/Testimonials.tsx"
export function Testimonials({ id }: { id: string }) {
  return <div data-sitebackend-widget={id} />;
}
```

Use it anywhere:

```tsx title="src/pages/Home.tsx"
import { Testimonials } from "../components/Testimonials";

export function Home() {
  return (
    <main>
      <h2>What our customers say</h2>
      <Testimonials id="w_YOUR_WIDGET_ID" />

      <h2>Leave a testimonial</h2>
      <Testimonials id="c_YOUR_COLLECT_ID" />
    </main>
  );
}
```

Leave the `div` empty. The script puts the widget inside it, and React doesn't touch children it didn't render.

## Routing and changing IDs

The script watches the page. When the router shows a new page with a widget, or the `id` prop changes, the widget loads without any extra code. It works the same in React's Strict Mode.

## Local development

Widgets work on `localhost:5173` even when your site has a **domain** set in the dashboard: `localhost` and `127.0.0.1` are always allowed. Preview or staging addresses on other domains are blocked, though. See [sites](https://sitebackend.com/docs/getting-started/sites).
