# useHydrated (/docs/hooks/use-hydrated)





`useHydrated` tells you whether the component is past hydration. Use it to hold back anything that only the browser can render — a value read from `window`, a widget that measures the DOM, a third-party embed — until React can show it without a hydration mismatch.

```tsx
import { useHydrated } from '@42-central/ui-react';

const hydrated = useHydrated();
return hydrated ? <LiveClock /> : <ClockSkeleton />;
```

## Usage [#usage]

The viewport size below only exists in the browser. On a server-rendered page the first paint shows `…`, the same text the server sent, then the real size replaces it.

<Preview code="&#x22;const hydrated = useHydrated();\n\n<p>{hydrated ? `${window.innerWidth} × ${window.innerHeight} viewport` : '…'}</p>&#x22;">
  <HydratedDemo />
</Preview>

A `ClientOnly` wrapper is three lines on top of it:

```tsx
function ClientOnly({ children, fallback = null }: { children: ReactNode; fallback?: ReactNode }) {
  return useHydrated() ? children : fallback;
}
```

## API [#api]

```ts
function useHydrated(): boolean
```

| Where it renders                             | Returns                      |
| -------------------------------------------- | ---------------------------- |
| On the server                                | `false`                      |
| The hydration render in the browser          | `false`                      |
| Every render after that                      | `true`                       |
| An app rendered only in the browser (no SSR) | `true` from the first render |

## How it works [#how-it-works]

It is `useSyncExternalStore` over a store that never changes: the server snapshot is `false`, the client snapshot is `true`. React uses the server snapshot for the server render and for hydration, so both emit the same markup, then re-renders with the client snapshot straight away. Unlike a `useState(false)` + `useEffect` pair, a component that mounts after hydration (a modal opened later, a client-side route change) gets `true` on its first render, with no extra frame of fallback.

The kit's own SSR-safe hooks ([`useMediaQuery`](/docs/hooks/use-media-query), [`useApplePlatform`](/docs/hooks/use-apple-platform), [`useNow`](/docs/hooks/use-now)) follow the same pattern with a real value in place of `true`. If what you need is one browser value, prefer a hook that returns it directly.
