# RefSubject.hydrate

Creates a named hydrated RefSubject using a string-encoded Schema codec.

## Signatures

```ts
export declare function hydrate<S extends Schema.Codec<any, string, any, any>, E = never, R = never>(schema: S, effect: HydrationInput<NoInfer<Schema.Schema.Type<S>>, E, R>, options: HydrateOptions<Schema.Schema.Type<S>> & {
    readonly name: string;
}): HydrateEffect<S, E, R>;
```

```ts
export declare function hydrate<S extends Schema.Top, E = never, R = never>(schema: S, effect: HydrationInput<NoInfer<Schema.Schema.Type<S>>, E, R>, options?: HydrateOptions<Schema.Schema.Type<S>> & {
    readonly name?: undefined;
}): HydrateEffect<S, E, R>;
```

## Why

Creates state whose server value is Schema-encoded and whose browser value is Schema-decoded
before the initializer resumes.

## Ownership and lifetime

The creation Effect requires Scope; that Scope owns initializer subscriptions and deferred
server/client coordination. Schema errors and codec services remain typed.

Values, Effects, Effect Streams, and Fx are accepted as initializers. A named string codec uses
its own `data-*` attribute; unnamed values share the versioned `data-typed-refsubject` envelope.
See {@link https://effect.website/docs/schema/introduction/ Effect Schema} for the codec and
service model used by this boundary.

## Synchronous configuration errors

Supplying an empty name, the reserved `typed-refsubject` name, or a name containing characters
forbidden in an HTML attribute throws `TypeError` immediately while `hydrate` is called. These
programmer errors are outside the returned Effect's typed error channel. Schema decoding and
encoding failures remain `Schema.SchemaError`, and codec requirements remain typed services.

## Examples

```ts
import { Effect, Schema } from "effect"
import * as Hydration from "@typed/fx/RefSubject"
import { RefSubject } from "@typed/fx"

const attributes = Effect.scoped(Effect.gen(function* () {
  const count = yield* Hydration.hydrate(Schema.FiniteFromString, 0, { name: "count" })
  yield* RefSubject.update(count, (value) => value + 1)
  return yield* count[Hydration.HydrationRefTypeId].toAttributes
}))
```
