function / @typed/ui/index

Form.makeState

Creates a Scope-owned hydrated form RefSubject from a Struct codec.

Learn this UI primitive →

Package version
1.0.0-beta.13
Category
State construction
Since
1.0.0
Member of
Form

Import

import { Form } from "@typed/ui/index";

Access Form.makeState through the imported Form export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

Signatures

export declare function makeState<const Fields extends FormFields>(codec: Schema.Struct<Fields>, initial: InitialStateFor<Fields>): Effect.Effect<RefSubject.HydratedRefSubject<{
    readonly values: Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>>;
    readonly defaultValues: Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>>;
    readonly errors: Schema.Struct.View<OptionalFields<Fields, Schema.String>, "Type", Schema.Struct.TypeOptionalKeys<OptionalFields<Fields, Schema.String>>, Schema.Struct.TypeMutableKeys<OptionalFields<Fields, Schema.String>>>;
    readonly meta: Schema.Struct.View<OptionalFields<Fields, Schema.Struct<{
        readonly dirty: Schema.Boolean;
        readonly touched: Schema.Boolean;
    }>>, "Type", Schema.Struct.TypeOptionalKeys<OptionalFields<Fields, Schema.Struct<{
        readonly dirty: Schema.Boolean;
        readonly touched: Schema.Boolean;
    }>>>, Schema.Struct.TypeMutableKeys<OptionalFields<Fields, Schema.Struct<{
        readonly dirty: Schema.Boolean;
        readonly touched: Schema.Boolean;
    }>>>>;
    readonly submitting: boolean;
}, Schema.SchemaError, never, Schema.Struct.DecodingServices<{
    readonly values: Schema.Struct<Fields>;
    readonly defaultValues: Schema.Struct<Fields>;
    readonly errors: Schema.Struct<OptionalFields<Fields, Schema.String>>;
    readonly meta: Schema.Struct<OptionalFields<Fields, Schema.Struct<{
        readonly dirty: Schema.Boolean;
        readonly touched: Schema.Boolean;
    }>>>;
    readonly submitting: Schema.Boolean;
}> | Schema.Struct.EncodingServices<{
    readonly values: Schema.Struct<Fields>;
    readonly defaultValues: Schema.Struct<Fields>;
    readonly errors: Schema.Struct<OptionalFields<Fields, Schema.String>>;
    readonly meta: Schema.Struct<OptionalFields<Fields, Schema.Struct<{
        readonly dirty: Schema.Boolean;
        readonly touched: Schema.Boolean;
    }>>>;
    readonly submitting: Schema.Boolean;
}>> & {
    codec: Schema.Struct<Fields>;
    fields: Fields;
    id: string;
}, never, Scope.Scope>;

Examples

import { makeState } from "@typed/ui/Form"
import { Effect, Schema } from "effect"

const codec = Schema.Struct({ email: Schema.String })
const program = Effect.gen(function* () {
  const state = yield* makeState(codec, { id: "signup", values: { email: "" } })
  return state
})

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source