Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

createForm.md

43 lines978 Bytes

const createForm: CreateFormHook;

Defined in: packages/solid-form/src/createForm.public.ts:62

Creates a Solid form whose instance and lifecycle are owned by the current reactive owner.

Pass an options accessor. defaultValues establish the initial state and inferred form value type, while signals read by the accessor update the same form instance when they change. The form is cleaned up when its owner is disposed.

Example

function ProfileForm() {
  const form = createForm(() => ({
    defaultValues: { name: '' },
    onSubmit: ({ value }) => saveProfile(value),
  }))

  return (
    <form
      onSubmit={(event) => {
        event.preventDefault()
        void form.handleSubmit()
      }}
    />
  )
}

Returns

The Solid form API with typed field, subscription, and form-group components attached.