Skip to main content
The ClientGate component ensures content is rendered only after JavaScript has loaded client-side, with optional fallback support for server-side rendering or no-JS environments.

When to Use

  • Render components that depend on browser APIs (window, document, etc.)
  • Prevent hydration mismatches from client-only features
  • Show skeleton loaders during hydration
  • Progressively enhance server-rendered content
  • Handle components that require JavaScript to function

Basic Usage

Component API

React.ReactNode | (() => React.ReactNode)
required
Content to render after client-side hydration. Can be a render function for deferred initialization
React.ReactNode
Content to show during SSR or before hydration. Should match the dimensions of the hydrated content to avoid layout shift
You are encouraged to add a fallback that matches the dimensions of the client-rendered children to avoid content layout shift.

Examples

Browser API-Dependent Component

Chart with Skeleton Fallback

Third-Party Widget

Window Size Dependent Component

Comparison to Native Patterns

Traditional Approach

With ClientGate

Common Use Cases

Progressive Enhancement

Preventing Hydration Mismatches

Avoid using ClientGate for content that should be SEO-friendly. The fallback is what search engines will see.

Implementation Details

The component uses the useIsHydrated hook internally to detect when the client has hydrated: