Next.js

Here’s the updated content with paraphrased comments in the code examples:


Integration with Next.js

Because Next.js uses server-side rendering (SSR) and wallet libraries require client-side handling, the Bando Widget must be rendered on the client side. To achieve this, you should use the 'use client' directive, which ensures the widget is loaded only in the client environment, bypassing SSR.

Here’s the setup for integrating the Bando widget with Next.js:

"use client";

import type { WidgetConfig } from "@bandohq/widget";
import { BandoWidget, WidgetSkeleton } from "@bandohq/widget";
import { ClientOnly } from "./ClientOnly";

export function Widget() {
  const config = {
    appearance: "light",
    theme: {
      container: {
        boxShadow: "0px 8px 32px rgba(0, 0, 0, 0.08)",
        borderRadius: "16px",
      },
    },
  } as Partial<WidgetConfig>;

  return (
    <div>
      {/* Renders the widget only after JavaScript is active on the client side, displaying the fallback during the server-side render */}
      <ClientOnly fallback={<WidgetSkeleton config={config} />}>
        <BandoWidget config={config} integrator="nextjs-example" />
      </ClientOnly>
    </div>
  );
}

Using 'use client' at the beginning of your component file ensures the widget operates strictly on the client side, making it compatible with SSR in Next.js.

Last updated