function / @typed/ui

Form.Form

Renders a native form and provides its state to bound descendants.

Learn this UI primitive →

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

Import

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

Access Form.Form 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 Form<const Values extends object, E, R, const Options extends FormOptions<Values, E, R>, const Host extends HostResult = never>(options: Options & Pick<FormOptions<Values, E, R>, "state" | "content">, host?: Dom.HostOverride<Dom.RenderHostProps<Options, FormProps<Values, E, R, Options>>, Options["content"], Host>): SchemaBoundRootResult<Options, Host>;

Examples

import { Form, Submit, TextInput, makeState } from "@typed/ui/Form"
import { Effect, Schema } from "effect"
import { html } from "@typed/template"

const codec = Schema.Struct({ email: Schema.String })
const view = Effect.gen(function* () {
  const state = yield* makeState(codec, { id: "signup", values: { email: "" } })
  return Form({
    state,
    content: html`${TextInput({ state, name: "email" })}${Submit({ content: "Join" })}`,
    onValidSubmit: (values) => Effect.log(`Submitting ${values.email}`)
  })
})

Other public imports

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

Source