Developer installation guide
How to embed Google reviews in React (Vite or CRA)
Load the saved widget when the review component appears, then clear its generated display when that component leaves the page.
Updated November 2026
Quick answer
- Simplest: add
<div data-verifiedwidget-id="YOUR_WIDGET_ID" />in your component, and loadhttps://verifiedwidget.com/widget.jsonce inindex.html(withoutdata-widget-id). - Or use the
GoogleReviewscomponent below, which loads the dashboard script itself and removes it on unmount. - Deploy and check the real URL.
Both routes work in Vite and Create React App (CRA). The React team deprecated CRA in February 2025, but existing CRA apps still run this code. Pick one, not both, or you will see two widgets.
Prepare a real widget first
In VerifiedWidget, connect a business with its Google Maps link. Confirm that its imported reviews are visible, make a widget, choose a layout, and save it. Open the Embed dialog and copy the code. The dashboard gives you this format: a placeholder div with a short text summary of your reviews, then the loader script. The ID shown here is an example only, so use the ID in your own code:
<div data-verifiedwidget-id="c123456789012345678901234">
<!-- a short plain-text summary of your reviews sits here -->
</div>
<script src="https://verifiedwidget.com/widget.js" crossorigin="anonymous" async></script>The script address and attributes are public install code. They do not expose a private Google API key. In a static HTML file, you can paste that code exactly. The text summary is there for search and AI crawlers that do not run JavaScript; the widget removes it once the reviews draw. React builds its pages in the browser, so leave the summary out of your components. In a React page, the review area may be mounted after the browser first loads, and navigation may swap components without reloading the document. A component can load the script at the right time and remove the generated display on cleanup.
Simpler option: a placeholder
Load the script once in index.html (in the project root for Vite, or public/index.html in Create React App). It is the last line of the dashboard code, with no widget ID on it. It then fills any element marked with data-verifiedwidget-id, including ones React adds later when a route changes. No effect or cleanup code is needed, because the loader watches for new placeholders and React removes the element (and its reviews) when the component unmounts.
<!-- index.html: load the loader once, without data-widget-id -->
<script src="https://verifiedwidget.com/widget.js" crossorigin="anonymous" async></script>export function GoogleReviews() {
return (
<section aria-labelledby="reviews-heading">
<h2 id="reviews-heading">Customer reviews</h2>
<div data-verifiedwidget-id="c123456789012345678901234" style={{ minHeight: 320 }} />
</section>
);
}Keep the placeholder element empty; do not render children into it. The ID shown is an example, so use your own widget ID. Do not also paste the full dashboard code for the same widget elsewhere in the app.
Or load the script from a component
Create GoogleReviews.tsx in your Vite or Create React App project. The code below uses only React and browser APIs. Change WIDGET_ID to the ID in your dashboard code (the value of data-verifiedwidget-id). Keep the address, crossOrigin, and async settings from that code. The loader also accepts the ID as data-widget-id on the script itself, which is what this component uses. If you use JavaScript instead of TypeScript, remove <HTMLDivElement> from the ref.
import { useEffect, useRef } from "react";
const WIDGET_ID = "c123456789012345678901234"; // Replace with your widget ID.
export function GoogleReviews() {
const hostRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const host = hostRef.current;
if (!host) return;
const script = document.createElement("script");
script.src = "https://verifiedwidget.com/widget.js";
script.dataset.widgetId = WIDGET_ID;
script.crossOrigin = "anonymous";
script.async = true;
host.appendChild(script);
return () => {
script.remove();
host.replaceChildren();
};
}, []);
return <div ref={hostRef} style={{ minHeight: 320 }} aria-label="Customer reviews" />;
}useEffect runs in the browser after React has put the empty host element on the page. The loader reads data-widget-id from the script as it runs and inserts its display beside that script inside the host. The host ref keeps React from trying to manage the review cards that the external loader creates. The cleanup removes both the script and its generated display when the component unmounts.
The minimum height is a starting point for a grid or carousel. Adjust it for your actual layout and phone width. A floating badge needs none, because it sits in a screen corner; a long list needs more.
Render it on the intended route
Import the component on the page where reviews belong. Put a normal heading outside the widget so the section has context even before the script loads. For example:
import { GoogleReviews } from "./GoogleReviews";
export function HomePage() {
return (
<main>
<h1>Welcome to our business</h1>
<section aria-labelledby="reviews-heading">
<h2 id="reviews-heading">Customer reviews</h2>
<GoogleReviews />
</section>
</main>
);
}The bundler does not change the embed code. Publish the app and check its actual URL, not just the development preview.
Place the component only on routes that should show reviews. A router may keep a parent layout mounted while child pages change. If you put the component in that persistent layout, it will stay visible on every child route. If you put it in the specific review page, it unmounts when you leave and remounts when you return. That lifecycle is what the cleanup above is designed for.
Handle single-page navigation and development reloads
React routers normally change the visible page without a full browser refresh. A script that carries the widget ID (data-widget-id) in index.html loads before the review route appears. With no placeholder on the page, it adds the reviews at the end of the page instead. Loading it from the route component means the script arrives with the section. When visitors leave, the cleanup clears the old cards. When they navigate back, the new component loads its own script and display.
React's development Strict Mode can run an effect setup, its cleanup, and setup again to check that cleanup works. You may see extra script activity in development. The code clears the first host before the next setup; check the production build before judging duplicate behavior. If a route stays mounted while only its contents change, key the review component to the route or ensure the host is recreated at the intended position. Do not append several copies of the script to the same host without removing the previous one.
Do not mix the two methods for the same widget: a placeholder plus a script with its own widget ID produces a duplicate display.
Floating layouts, such as the badge, pop-up and side tab, work a little differently. The loader moves them to the end of the page body so they can float over the page. It watches the spot where they started, and removes the floating copy when React removes that spot. So a route change does not leave a stray badge behind. If you want the badge on every route, render it once in a layout that stays mounted.
Security and loading checks
If your deployment uses a Content Security Policy, allow https://verifiedwidget.com in both script-src and connect-src. The first covers widget.js and a second small file some layouts need; the second covers its review-data request. If you choose a custom font, the widget loads it from Google Fonts, so allow fonts.googleapis.com in style-src and fonts.gstatic.com in font-src. Review images may use other hosts, so inspect the browser console before changing img-src. Do not place a secret Google key in a Vite VITE_ variable or a Create React App REACT_APP_ variable: those values are bundled for visitors. The widget embed needs no such key in your app.
Test desktop and phone widths after publishing. Confirm review names, dates, links, and any media match the connected business. If you have enabled a domain allowlist, add your live domain. That also covers its subdomains, such as www or staging. A preview on a different address, such as your hosting provider's preview URL, must be added on its own. If you use a consent manager or browser extension that blocks outside scripts, test the intended visitor path and confirm the widget eventually appears.
Is there a React package for Google reviews?
You do not need one. There is no npm package to install for this method. The component above is a few lines, and the widget code itself is loaded from VerifiedWidget at run time. That means no extra dependency to keep updated, and the display improves without you changing your app. It also works in Vite, Create React App, Remix and Gatsby, as long as the component runs in the browser.
react-google-reviews vs a hosted widget
If you searched for react-google-reviews, you probably found the npm package of that name. It is an open-source React component published by Featurable, another review widget company. Its GitHub readme says it can fetch reviews through the Google Places API or through Featurable's own API, using a widget ID from a Featurable account. So it is a dependency in your bundle that still relies on an outside service for the reviews.
The method on this page goes the other way: there is no package in your bundle, and the layout and reviews come from your VerifiedWidget dashboard. Pick the package if you want to style every card in your own React code. Pick a hosted widget if you want to change layouts, hide reviews or switch businesses without a new deploy. Either way, Google's Places API on its own returns at most 5 reviews per place; see the Google reviews API guide.
React or Google Places API: which should you pick?
Using Google's API from React means a Google Cloud key, billing, a server to keep the key private, and your own styling. Google's place details only return a few reviews, so many builders find the result thin. A widget gives you ready-made layouts and updates. If you still want the direct route, start with the Google Reviews API guide.
TypeScript, server rendering and testing
In TypeScript, the element reference is typed as HTMLDivElement and nothing else needs types. If your framework renders on the server, keep the script loading inside useEffect so it only runs in the browser. In unit tests, mock or skip the component, since the widget needs a real browser and network. For a Next.js App Router project, the Next.js guide uses next/script instead.
Troubleshoot a missing or duplicate widget
If the section is blank, inspect the page after deployment. Confirm the ID is your saved widget ID and that the component actually mounted on that route. In the browser network panel, look for widget.js and the /api/embed/ request. A blocked script points to the browser or script-src; a blocked data call can point to connect-src or domain restrictions. The loader also prints a console line starting with [VerifiedWidget]. It names the cause: a 403 for a domain that is not allowed, a 404 for an unknown widget, or a 429 when requests arrive too quickly.
If the calls succeed but there are no cards, check that the widget has imported reviews and that its filters have not hidden every review. If two copies appear, search the project for another embed in index.html, a persistent layout, or a second component. If the display appears on the wrong route, check where the component is rendered and whether a parent layout remains mounted during navigation. If the review area is clipped, inspect the host section's width and overflow.
If your app uses the Next.js App Router, follow the Next.js guide instead. For Google star results, see our star ratings guide.
Frequently asked questions
Is there an npm package for the Google reviews widget?
No package is needed. You add a small component that loads the widget script, so there is nothing extra to install or update.
Does it work with TypeScript?
Yes. Type the element reference as HTMLDivElement and the rest is plain DOM code.
Does a floating badge stay behind after a route change?
No. The loader removes a floating badge when React removes the element it started in. Render it in a layout that stays mounted if it should show on every route.
Does this work with server-side rendering?
Keep the script loading inside useEffect so it runs only in the browser. The server then renders just the empty container.
Does this work with Vite and Create React App?
Yes. The example needs React, a browser, and your saved widget ID; the bundler does not change the embed format.
Why load the script in useEffect?
The effect runs after the host element exists in the browser, so the loader can place reviews inside the right component on that route.
What happens when a visitor changes routes?
The component cleanup removes the previous script and display. Returning to the route mounts a fresh component and loads the widget again.
Why do I see two widgets during development?
Check for an additional script in index.html or a parent layout. React Strict Mode also repeats effect setup in development, so verify the production build.
Can I put a Google API key in a React environment variable?
Do not put a private key in client-side React configuration. The VerifiedWidget embed only needs the public widget ID and script URL.
Show real reviews in your React app
Create a free widget, copy its ID, and add the component to the route where visitors should see it.