Skip to content

dehydrate · Next.js server API

function dehydrate<TSchema>(options): HydrationSnapshot<TSchema>;

Reads serializable snapshots from hydratable entities declared in a schema.

Use this on the server side before crossing into a Client Component. Only the returned snapshot should cross the boundary, not the container or service instances themselves.

Type Parameter

TSchema extends Readonly<Record<string, Token<Hydratable<Serializable>>>>

Parameter Type Description

options

DehydrateOptions<TSchema>

Container and schema describing state to serialize.

HydrationSnapshot<TSchema>

A serializable snapshot inferred from the schema.

const hydration = { user: USER_STATE };
const snapshot = dehydrate({
container: getRequestContainer(),
schema: hydration,
});

Error when the schema contains a missing token.