Skip to main content

Overview

The ClientGate component ensures that its children are only rendered after JavaScript has loaded on the client side. This is useful for preventing hydration mismatches and for components that require browser APIs.

Import

Props

React.ReactNode | (() => React.ReactNode)
required
The content to render only on the client side. Can be a render function for lazy evaluation.
React.ReactNode
Content to render on the server or before hydration. It’s recommended to use a fallback with the same dimensions as the client-rendered children to avoid content layout shift.

Usage Examples

Basic Usage

With Render Function

Preventing Layout Shift

In this example, FakeChart should have the same dimensions (400x300) as RealChart to prevent layout shift during hydration.

Browser-Only Components

Multiple Client-Only Sections

Notes

  • The component uses the useIsHydrated hook internally to detect when the client has hydrated
  • When no fallback is provided, nothing is rendered on the server
  • Using a fallback with matching dimensions prevents Cumulative Layout Shift (CLS)
  • Render functions are useful for lazy loading or accessing browser-only APIs