Openlaud

A Next.js testimonials component

Last updated

A Next.js testimonials component can fetch your Openlaud wall as HTML on the server and put it straight into the page. The testimonial text is then in the HTML your server sends, so it loads with the page and search engines read it. Next.js caches the result and refreshes it on the interval you set.

How do I add server-rendered testimonials to Next.js?

  1. In Openlaud, create a wall and choose its layout and colours.
  2. Copy the wall key from "Put it on your website".
  3. Add the server component below to your App Router project.
  4. Render it on any page, such as <Testimonials /> on your home page.
  5. Deploy and check the page source: the testimonial text is in the HTML.
// app/components/testimonials.tsx: a server component, no "use client"
export async function Testimonials() {
  const res = await fetch("https://openlaud.com/api/public/walls/YOUR_WALL_KEY.html", {
    next: { revalidate: 3600 },
  });
  if (!res.ok) return null;
  // Openlaud escapes every value and the HTML has no scripts.
  return <div dangerouslySetInnerHTML={{ __html: await res.text() }} />;
}

If you self-host Openlaud, use your own domain in the address.

What about the React component?

The repository includes TestimonialWall, an MIT-licensed React server component that does the same with error handling and a revalidate prop. It is not published to npm yet, so the fetch example above is the quickest way to start.

Script embed or server rendering?

  • Server rendering: best for SEO and speed. Updates on your revalidate interval or next build.
  • Script embed: a <div> and a <script> tag. Updates within minutes, but the text loads after the page.

More on that choice in do testimonials help SEO?.

To collect your first testimonials, read how to ask for a testimonial. Building with a site builder instead? See the guides for Webflow, Framer and WordPress.

Questions people ask

+Why render testimonials on the server in Next.js?

The testimonial text is in the HTML your server sends, so it shows without waiting for a script, does not shift the layout, and search engines read it with the page.

+Is it safe to use dangerouslySetInnerHTML here?

The wall HTML comes from Openlaud with every value escaped and no scripts. Only use it with the wall address from your own Openlaud account or instance.

+How often does the wall refresh?

As often as the revalidate value says, in seconds. With revalidate set to 3600, a testimonial you approve appears within an hour, and one you remove disappears within an hour.

+Is there an npm package?

The MIT-licensed React component lives in the Openlaud repository and is not on npm yet. The fetch example on this page needs no package.

+Does it work with the Pages Router?

Yes. Fetch the same address in getStaticProps with a revalidate value and render the HTML in the page.