ClientOnly

ClientOnly is a component that renders its children only on the client side.

Usage

import { ClientOnly } from "@yamada-ui/react"
<ClientOnly />

Fallback

To render a loading state while child elements are being prepared, use the fallback prop.

Render Prop

When your component accesses browser-only APIs like window, document, localStorage, use the render prop pattern. This pattern ensures that components accessing browser APIs are evaluated only on the client side, preventing hydration mismatches and server-side errors.
It can also be used for rendering heavy components that are not needed on the server side.

/* This may cause server-side errors */
<ClientOnly fallback={<Skeleton />}>
  <ComponentThatUsesWindow />
</ClientOnly>

/* This is safe */
<ClientOnly fallback={<Skeleton />}>
  {() => <ComponentThatUsesWindow />}
</ClientOnly>

Props