Skip to content
@pyreon/form
fundamentals · forms

Type in one field. The other eleven never notice.

Every field's value, error, touched and dirty flag is its own signal, so a keystroke updates one input and nothing else. On a 12-field form against six popular form libraries, it was the fastest at all four timed operations.

bun add @pyreon/form
Documentation
re-renders
0 per 10 keystrokesFormik: 10. Fields update in place.
schemas
Zod, Valibot, ArkType, sPassed straight to schema. No resolver package.
accessibility
built into register()id, aria-invalid, aria-describedby; focus jumps to the first error.
native
iOS and Android, experimentaluseForm and useFieldArray compile to native form state.
Type in one field; the other eleven never update A twelve-field form. Letters are typed into the email field one keystroke at a time; each keystroke pulses only the email input and its message, which reads "invalid" until the address is complete and then shows a check mark. The other eleven fields stay still and a counter reads 0 updates for them. USEFORM · 12 FIELDS · ONE KEYSTROKE emailaadadaada@ada@pyada@pyreonada@pyreon.devinvalid✓namephonecompanystreetcityzipcountrypasswordconfirmplannotes email idle updates on every key other 11 fields: 0 updates
  • 210 µs to mount a 12-field form. React Hook Form: 640 µs. TanStack Form: 680 µs.BENCHMARKS.md §6 form-bench, overnight run 2026-11-05, one run, real Chromium, M3 Max
  • 460 µs per validating keystroke. React Hook Form: 830 µs. Formik: 1,320 µs.BENCHMARKS.md §6 form-bench, keystroke (change mode, validates), one run
  • 9× faster reset of a dirty form than React Hook Form (20 vs 180 µs).BENCHMARKS.md §6 form-bench, reset dirty form, one run

synthetic · author-run · M3 Max · record of 2026-11-05

Every result, including where we lose →
why teams pick it

The form code you keep rewriting, already written.

  1. A keystroke touches one field

    Value, error, touched and dirty are four separate signals per field. Typing in email updates the email input and its error text; the password field, the submit button and the other ten fields stay put. Formik re-renders its whole form 10 times for 10 keystrokes; this does 0.

  2. Async checks can't race

    Async validators are versioned and receive an AbortSignal. When the user types faster than your server answers, the late answer is dropped instead of overwriting the newer one. debounceMs: 300 cuts the requests too.

  3. Your schema, as it is

    Hand schema a raw Zod, Valibot or ArkType schema, or @pyreon/validate's s. No resolver package. An error on address.city lands on the address.city field, and a key that matches no field fails the form instead of vanishing.

  4. Accessible by default

    One register('email') spread gives the input an id, aria-invalid and aria-describedby that follow the error. A failed submit moves focus to the first broken field, like React Hook Form's shouldFocusError.

the difference

Delete the debounce, the race guard and the effect.

React, an async check by hand

A ref to drop stale answers, a timer to debounce, an effect with a dependency array. Per async field.

import { useEffect, useRef, useState } from 'react'

function EmailField() {
  const [email, setEmail] = useState('')
  const [error, setError] = useState<string>()
  const latest = useRef(0)

  useEffect(() => {
    const id = ++latest.current
    const t = setTimeout(async () => {
      const taken = await checkEmail(email)
      if (id === latest.current) setError(taken ? 'Already registered' : undefined)
    }, 300)
    return () => clearTimeout(t)
  }, [email])

  return (
    <>
      <input value={email} onChange={(e) => setEmail(e.target.value)} />
      {error && <span>{error}</span>}
    </>
  )
}
with @pyreon/form

Declare the check. Debounce, stale-result discarding and the abort signal are built in.

import { useForm } from '@pyreon/form'

const form = useForm({
  initialValues: { email: '', password: '' },
  validators: {
    email: async (v, _all, signal) =>
      (await checkEmail(v, signal)) ? 'Already registered' : undefined,
    password: (v) => (v.length < 8 ? 'At least 8 characters' : undefined),
  },
  validateOn: 'change',
  debounceMs: 300,
  onSubmit: (values) => api.signup(values),
})
coming from

Coming from React Hook Form or Formik?

Same shape, minus the resolver and the formState destructure.

React Hook Form
import { useForm } from 'react-hook-form'
import { zodResolver } from '@hookform/resolvers/zod'
import { z } from 'zod'

const schema = z.object({
  email: z.email('Enter a valid email'),
  password: z.string().min(8, 'At least 8 characters'),
})
type Values = z.infer<typeof schema>

function SignUp() {
  const {
    register, handleSubmit, setError,
    formState: { errors, isSubmitting },
  } = useForm<Values>({ resolver: zodResolver(schema), mode: 'onBlur' })

  const onSubmit = async (values: Values) => {
    const res = await api.signup(values)
    if (res.emailTaken) setError('email', { message: 'Already registered' })
  }

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...register('email')} />
      {errors.email && <span>{errors.email.message}</span>}
      <input type="password" {...register('password')} />
      {errors.password && <span>{errors.password.message}</span>}
      <button disabled={isSubmitting}>Sign up</button>
    </form>
  )
}
Pyreon

register() reads the same. The Zod schema goes in as it is, and setErrors replaces setError. Each error line is its own reactive text, so a new error repaints one <span>.

import { useField, useForm } from '@pyreon/form'
import { z } from 'zod'

const schema = z.object({
  email: z.string().email('Enter a valid email'),
  password: z.string().min(8, 'At least 8 characters'),
})

function SignUp() {
  const form = useForm({
    initialValues: { email: '', password: '' },
    schema,
    onSubmit: async (values) => {
      const res = await api.signup(values)
      if (res.emailTaken) form.setErrors({ email: 'Already registered' })
    },
  })
  const email = useField(form, 'email')
  const password = useField(form, 'password')

  return (
    <form onSubmit={form.handleSubmit}>
      <input {...email.register()} />
      {() => email.showError() && <span>{email.error()}</span>}
      <input type="password" {...password.register()} />
      {() => password.showError() && <span>{password.error()}</span>}
      <button disabled={form.isSubmitting}>Sign up</button>
    </form>
  )
}

Keep the validate logic, lose the render prop.

Formik
import { ErrorMessage, Field, Form, Formik } from 'formik'

function SignUp() {
  return (
    <Formik
      initialValues={{ email: '', password: '' }}
      validate={(v) => {
        const errors: { email?: string; password?: string } = {}
        if (!v.email.includes('@')) errors.email = 'Enter a valid email'
        if (v.password.length < 8) errors.password = 'At least 8 characters'
        return errors
      }}
      onSubmit={async (values, { setFieldError }) => {
        const res = await api.signup(values)
        if (res.emailTaken) setFieldError('email', 'Already registered')
      }}
    >
      {({ isSubmitting }) => (
        <Form>
          <Field name="email" type="email" />
          <ErrorMessage name="email" component="span" />
          <Field name="password" type="password" />
          <ErrorMessage name="password" component="span" />
          <button type="submit" disabled={isSubmitting}>Sign up</button>
        </Form>
      )}
    </Formik>
  )
}
Pyreon

Formik's validate becomes one validator per field. In form-bench Formik re-renders the whole form on each of 10 keystrokes; here nothing re-renders.

import { useForm } from '@pyreon/form'

function SignUp() {
  const form = useForm({
    initialValues: { email: '', password: '' },
    validators: {
      email: (v) => (v.includes('@') ? undefined : 'Enter a valid email'),
      password: (v) => (v.length < 8 ? 'At least 8 characters' : undefined),
    },
    onSubmit: async (values) => {
      const res = await api.signup(values)
      if (res.emailTaken) form.setFieldError('email', 'Already registered')
    },
  })
  const { email, password } = form.fields

  return (
    <form onSubmit={form.handleSubmit}>
      <input type="email" {...form.register('email')} />
      <span>{email.error()}</span>
      <input type="password" {...form.register('password')} />
      <span>{password.error()}</span>
      <button disabled={form.isSubmitting}>Sign up</button>
    </form>
  )
}
try it

Type fast and watch what re-renders.

The email check answers after 0.4 to 1.1 seconds, and "ada@example.com" is taken. Type fast and watch the counters: the password field never updates while you type an email, and every slow answer that arrives late is thrown away.

  • email field updates0
  • password field updates0
  • stale async results discarded0
  • requests sent (debounced 300 ms)0

Validation runs on blur by default. This demo validates as you type so you can see the debounce and the stale-result handling at work.

benchmarks

Fastest of seven form libraries on all four timed operations.

One 12-field form, one shared Zod schema, each library written the way its own docs recommend, inside its own framework. The closest rival is Solid's modular-forms, which also keeps the lightest heap.

vs Solid modular-forms, React Hook Form, Formik, vee-validate (Vue), Felte (Svelte), TanStack Form · real ChromiumPyreonrival · lower is better
  • mount 12 fields
    210 µs
    305 µs
    win1.45× vs modular-forms · 3.0× vs React Hook Form
  • keystroke, validating
    460 µs
    570 µs
    win1.24× vs modular-forms · 1.8× vs React Hook Form
  • keystroke, blur mode
    60 µs
    100 µs
    win1.67× vs modular-forms · 8.8× vs Formik
  • reset a dirty form
    20 µs
    35 µs
    win1.75× vs modular-forms · 9× vs React Hook Form
  • headless store update
    win62.4× vs TanStack form-core (bun)
  • re-renders per 10 keystrokes
    measuredFormik 10 · React Hook Form 0
  • retained heap
    2.42 MB
    2.33 MB
    lossmodular-forms 0.09 MB lighter
Apple M3 Max · record of 2026-11-05 · overnight run, one run · author-run, syntheticFull method, every loss →
what's included

Everything a real form needs.

  • Typed from one declaration useForm({ initialValues, validators }) infers the value type of every field, validator and useField('name') read from initialValues.
  • Validate on blur, change or submit validateOn defaults to 'blur', so nobody is told off mid-word.
  • Async validators with debounceMs, an AbortSignal, and stale results discarded by version.
  • Cross-field rules every validator gets (value, allValues), so "must differ from email" is one line.
  • Field arrays with stable keys append, prepend, insert, remove, update, move, swap, replace; render with <For by={(i) => i.key}> and inputs keep focus when rows move.
  • Dot-path leaf fields 'address.city' is a real field; nestValues() turns the flat values into the nested payload your API wants.
  • Server errors in one call setErrors({ email: 'Already registered' }) shows them at once, touched or not.
  • Reset to what the server saved reset(saved) makes the saved values the new clean baseline; keepErrors, keepTouched, keepDirty keep what you choose.
  • Runtime fields registerField and unregisterField for forms built from data.
  • Typed inputs register(name, { type: 'checkbox' | 'number' | 'file' }) binds checked, valueAsNumber or the FileList.
recipes

Things to build with it.

A nested address, posted as nested JSON

Dot-path keys are real fields with their own validators and errors. nestValues() builds { name, address: { city, zip } } for the API.

import { nestValues, useForm } from '@pyreon/form'

function ProfileForm() {
  const form = useForm({
    initialValues: { name: '', 'address.city': '', 'address.zip': '' },
    validators: {
      'address.zip': (zip) => (/^\d{5}$/.test(zip) ? undefined : 'Five digits'),
    },
    // values stay flat; nest them at the API boundary
    onSubmit: (values) => api.saveProfile(nestValues(values)),
  })

  return (
    <form onSubmit={form.handleSubmit}>
      <input {...form.register('name')} />
      <input {...form.register('address.city')} />
      <input {...form.register('address.zip')} />
      <span>{form.fields['address.zip'].error()}</span>
      <button>Save</button>
    </form>
  )
}
An invite list that grows

useFieldArray gives every row a stable key, so removing row two never moves the cursor out of row three.

import { For } from '@pyreon/core'
import { useFieldArray } from '@pyreon/form'

function Invites() {
  const emails = useFieldArray<string>([''])

  return (
    <ul>
      <For each={emails.items} by={(item) => item.key}>
        {(item) => (
          <li>
            <input
              value={item.value()}
              onInput={(e) => item.value.set(e.currentTarget.value)}
            />
            <button type="button" onClick={() => emails.remove(emails.items().indexOf(item))}>
              Remove
            </button>
          </li>
        )}
      </For>
      <button type="button" onClick={() => emails.append('')}>Add another</button>
    </ul>
  )
}
An edit form that knows when it is saved

After a save, reset(saved) makes the server's copy the clean baseline. The Save button is disabled again until the next real change.

import { useForm } from '@pyreon/form'
type Post = { title: string; body: string }

function EditPost(props: { post: Post }) {
  const form = useForm({
    initialValues: props.post,
    onSubmit: async (values) => {
      const saved = await api.savePost(values)
      form.reset(saved) // the server's copy becomes the new clean baseline
    },
  })

  return (
    <form onSubmit={form.handleSubmit}>
      <input {...form.register('title')} />
      <textarea {...form.register('body')} />
      <button disabled={() => !form.isDirty() || form.isSubmitting()}>Save</button>
    </form>
  )
}
api

12 runtime exports, plus types.

Every export has a reference page with its signature, an example and the mistakes people make with it.

create · 3
  • useForm
  • field
  • useFieldArray
read · 3
  • useField
  • useWatch
  • useFormState
share · 4
  • FormProvider
  • useFormContext
  • Form
  • Submit
nested data · 2
  • nestValues
  • flattenValues
types · 7
  • FormState
  • FieldState
  • UseFormOptions
  • FormValues
  • FieldNames
  • FieldValue
  • NestValues
good to know

Good to know before you start.

Validation waits for blur

That is the default, so people aren't corrected mid-word. For live feedback set validateOn: 'change' and add debounceMs if a validator calls your server.

Key array rows by item.key

Each useFieldArray item carries a stable key. Use it in <For by>; an index key makes inputs lose focus when rows move.

Dot-path values stay flat

values() and onSubmit keep 'address.city' as one key. Convert at the API boundary with nestValues(); a nested schema needs an as never cast until deep-path types land.

Typed <Form of> in strict TSX

Today <Form of={form}> rejects a typed form under strict. Until that is fixed, write <form onSubmit={form.handleSubmit}> or wrap with <FormProvider form={form}>, both of which type cleanly.

questions

What people ask first.

Is the benchmark measuring the form library or the framework?

Both, on purpose. Each library runs in its own framework, written the way its docs recommend, with one shared Zod schema, in real Chromium. That is the cost you ship. It is one overnight run on one machine and we wrote the bench, so the harness is in the repo: cd examples/form-bench && bun bench-form.ts.

Do I need an adapter for Zod?

No. Any Standard Schema (Zod 3.24+, Valibot 1+, ArkType 2+, @pyreon/validate) goes straight into schema. The zodSchema() adapters in @pyreon/validation remain for when you want them.

What happens to a schema error for a field I didn't declare?

It is never dropped. A nested error goes to the closest declared parent field; an error that matches nothing marks the form invalid, sets submitError and warns in development.

Does it work with server-rendered pages?

Yes. The form state is plain signals that start from initialValues on both sides, and focusFirstError() is a no-op on the server. Input ids come from createUniqueId(), which matches between server HTML and the hydrated page from the next release on.

Can I watch one value without re-running on every field?

useWatch(form, 'email') returns that field's own signal. useFormState(form, (s) => s.isValid && s.isDirty) takes a selector so a button only recomputes when its inputs change.

Your form, minus the plumbing. The plumbing was most of it.

bun add @pyreon/form
Read the forms guide