Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

426 B
Raw Blame
import { type ReactNode, useSyncExternalStore } from "react";

export const ClientOnly = ({
  fallback,
  children,
}: {
  fallback?: ReactNode;
  children: ReactNode;
}) => {
  // https://tkdodo.eu/blog/avoiding-hydration-mismatches-with-use-sync-external-store
  const isServer = useSyncExternalStore(
    () => () => {},
    () => false,
    () => true
  );
  if (isServer) {
    return fallback;
  }
  return children;
};