--- title: ClientOnly description: "`ClientOnly` is a component that renders its children only on the client side." links: - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/client-only - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-clientonly--basic --- ```tsx } /> ``` ## Usage ```tsx import { ClientOnly } from "@yamada-ui/react" ``` ```tsx import { ClientOnly } from "@/components/ui" ``` ```tsx import { ClientOnly } from "@workspaces/ui" ``` ```tsx ``` ### Fallback To render a loading state while child elements are being prepared, use the `fallback` prop. ```tsx }> } /> ``` ### 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. ```tsx }> {() => ( Current URL: {window.location.href} Screen width: {window.innerWidth}px )} ``` :::warning While you can pass components directly, be careful with components that access browser APIs. ::: ```tsx /* This may cause server-side errors */ }> /* This is safe */ }> {() => } ``` ## Props | Prop | Default | Type | Description | | ---------- | ------- | --------------------- | -------------------------------------------------------------------------------------------------------------- | | `children` | - | `ReactNodeOrFunction` | The content to render on the client side. **Note:** Use the function pattern when accessing browser-only APIs. | | `fallback` | - | `ReactNode` | The fallback content to render while the component is mounting on the client side. |