import { useSyncExternalStore, type PropsWithChildren } from 'react';function subscribe() { return () => {};}/** * Return a boolean indicating if the JS has been hydrated already. * When doing Server-Side Rendering, the result will always be false. * When doing Client-Side Rendering, the result will always be false on the * first render and true from then on. Even if a new component renders it will * always start with true. */export function useHydrated() { return useSyncExternalStore( subscribe, () => true, () => false, );}interface ClientOnlyProps extends PropsWithChildren { fallback?: React.ReactNode;}/** * Render the children only after the JS has loaded client-side. Use an optional * fallback component if the JS is not yet loaded. */export function ClientOnly({ children, fallback = null }: ClientOnlyProps) { const hydrated = useHydrated(); return hydrated ? children : fallback;}
import { Widget } from './components/Widget';export default function Home() { return ( <main> <Widget /> </main> );}
If you are using Next.js with the Pages Router, you need to import the LI.FI Widget dynamically:
As you can see from the Next.js example, for users convenience we provide the WidgetSkeleton component that can be used as a fallback while the main widget component is being loaded.
The WidgetSkeleton component is currently only tested with中 Next.js environment and might not work with other SSR frameworks.