Skip to content

Client Only

Overview

ClientOnly renders its children only on the client side, after React hydration completes. During SSR, the optional fallback is rendered instead. This prevents hydration mismatches when using browser-only APIs.

Usage

import { isClient } from "@paramanu/utilities-js"
if (isClient()) {
// Safe to use browser APIs
document.title = "Updated"
}

Guidelines

  • Use to wrap components that depend on window, document, or localStorage
  • Provide a fallback for loading states during SSR
  • The useIsClient() hook provides the same functionality as a hook
  • Useful for wrapping Portals in SSR frameworks

API

PropTypeDefaultDescription
fallbackReactNodenullContent shown during SSR
childrenReactNode-Client-only content