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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
Container and schema describing state to serialize. |
Returns
Section titled “Returns”HydrationSnapshot<TSchema>
A serializable snapshot inferred from the schema.
Example
Section titled “Example”const hydration = { user: USER_STATE };const snapshot = dehydrate({ container: getRequestContainer(), schema: hydration,});Throws
Section titled “Throws”Error when the schema contains a missing token.