# Server

> For the complete documentation index, see [llms.txt](https://ensforge.com/llms.txt).

Look up the server rendering helpers of @ensforge/react/server, which prefetch ENS reads on the server so the client hydrates with data.

Source: https://ensforge.com/docs/reference/react/server

Exports of `@ensforge/react/server`, for prefetching reads on the server.

## Exports [#exports]

### `dehydrate` [#dehydrate]

**Unstable**

Prefetched reads of `registry` as plain data for `<HydrationBoundary state={…}>`.

```ts
function dehydrate(registry: AtomRegistry.AtomRegistry, options: { readonly streaming?: boolean | undefined } = {}): readonly Hydration.DehydratedAtom[]
```

- Values are JSON (bigints and bytes are tagged), so they pass through server components and
  loaders. Entries carry no `undefined` fields, so the result can be returned directly from
  Next.js `getServerSideProps` and `getStaticProps`.
- `streaming: true` also sends reads still loading, as promises that resolve on the client
  (React 19 server components, streaming SSR).

```tsx title="Streaming reads that are still loading"
import { Actions } from "@ensforge/sdk"
import { HydrationBoundary } from "@ensforge/react"
import { dehydrate, prefetch } from "@ensforge/react/server"
import { AtomRegistry } from "effect/reactivity"

const registry = AtomRegistry.make()
void prefetch(registry, ens, Actions.indexer.getSubnames, { name: "ens.eth" })
const state = dehydrate(registry, { streaming: true })
```

### `prefetch` [#prefetch]

**Unstable**

Runs a read on the server into `registry`, so `dehydrate` can send its result to the client.

```ts
function prefetch<action extends Action>(registry: AtomRegistry.AtomRegistry, client: Ensforge.Client, action: action, options: ActionOptions<action>, freshness?: Freshness): Promise<void>
```

Use in server components, loaders and `getServerSideProps`/`getStaticProps` for the reads a
page renders first. Reads that are not prefetched render as loading on the server and run in
the browser.

- Resolves once the read settles; a failed read is not sent, so the browser retries it.
- Do not await it when streaming (`dehydrate(registry, { streaming: true })`): pending reads
  then stream to the client as they resolve.
- Use a new registry per request.

```tsx title="Next.js App Router"
import { Actions } from "@ensforge/sdk"
import { HydrationBoundary } from "@ensforge/react"
import { dehydrate, prefetch } from "@ensforge/react/server"
import { AtomRegistry } from "effect/reactivity"

export default async function Page({ params }: { params: { name: string } }) {
  const registry = AtomRegistry.make()
  await prefetch(registry, ens, Actions.name.get, { name: params.name })
  return <HydrationBoundary state={dehydrate(registry)}>{params.name}</HydrationBoundary>
}
```