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";importtype { WidgetConfig } from"@bandohq/widget";import { BandoWidget, WidgetSkeleton } from"@bandohq/widget";import { ClientOnly } from"./ClientOnly";exportfunctionWidget() {constconfig= { appearance:"light", theme: { container: { boxShadow:"0px 8px 32px rgba(0, 0, 0, 0.08)", borderRadius:"16px", }, }, } asPartial<WidgetConfig>;return ( <div> {/* Renders the widget only after JavaScript is active on the client side, displaying the fallback during the server-side render */}
<ClientOnlyfallback={<WidgetSkeletonconfig={config} />}> <BandoWidgetconfig={config} integrator="nextjs-example" /> </ClientOnly> </div> );}
import { useSyncExternalStore,type PropsWithChildren } from"react";functionsubscribe() {return () => {};}/** * Determines if JavaScript has hydrated, indicating that it's client-rendered. * For SSR, it will always return false, but once hydrated on the client, * it remains true for subsequent renders. */exportfunctionuseHydrated() {returnuseSyncExternalStore( subscribe, () =>true, () =>false );}interfaceClientOnlyPropsextendsPropsWithChildren { fallback?:React.ReactNode;}/** * Only renders children components once JavaScript has loaded on the client. * Shows an optional fallback component until hydration is complete. */exportfunctionClientOnly({ children, fallback =null }:ClientOnlyProps) {consthydrated=useHydrated();return hydrated ? children : fallback;}
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.