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 - re-renders
- 0 per 10 keystrokesFormik: 10. Fields update in place.
- schemas
- Zod, Valibot, ArkType,
sPassed straight toschema. No resolver package. - accessibility
- built into
register()id,aria-invalid,aria-describedby; focus jumps to the first error. - native
- iOS and Android, experimental
useFormanduseFieldArraycompile to native form state.
- 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 →The form code you keep rewriting, already written.
A keystroke touches one field
Value, error, touched and dirty are four separate signals per field. Typing in
emailupdates 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.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: 300cuts the requests too.Your schema, as it is
Hand
schemaa raw Zod, Valibot or ArkType schema, or@pyreon/validate'ss. No resolver package. An error onaddress.citylands on theaddress.cityfield, and a key that matches no field fails the form instead of vanishing.Accessible by default
One
register('email')spread gives the input an id,aria-invalidandaria-describedbythat follow the error. A failed submit moves focus to the first broken field, like React Hook Form'sshouldFocusError.
Delete the debounce, the race guard and the effect.
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>}
</>
)
}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 React Hook Form or Formik?
Same shape, minus the resolver and the formState destructure.
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>
)
}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.
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>
)
}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>
)
}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.
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.
- mount 12 fields210 µs305 µswin1.45× vs modular-forms · 3.0× vs React Hook Form
- keystroke, validating460 µs570 µswin1.24× vs modular-forms · 1.8× vs React Hook Form
- keystroke, blur mode60 µs100 µswin1.67× vs modular-forms · 8.8× vs Formik
- reset a dirty form20 µs35 µswin1.75× vs modular-forms · 9× vs React Hook Form
- headless store updatewin62.4× vs TanStack form-core (bun)
- re-renders per 10 keystrokesmeasuredFormik 10 · React Hook Form 0
- retained heap2.42 MB2.33 MBlossmodular-forms 0.09 MB lighter
Everything a real form needs.
- Typed from one declaration
useForm({ initialValues, validators })infers the value type of every field, validator anduseField('name')read frominitialValues. - Validate on blur, change or submit
validateOndefaults to'blur', so nobody is told off mid-word. - Async validators with
debounceMs, anAbortSignal, 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,keepDirtykeep what you choose. - Runtime fields
registerFieldandunregisterFieldfor forms built from data. - Typed inputs
register(name, { type: 'checkbox' | 'number' | 'file' })bindschecked,valueAsNumberor theFileList.
Things to build with it.
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>
)
}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>
)
}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>
)
}12 runtime exports, plus types.
Every export has a reference page with its signature, an example and the mistakes people make with it.
- useForm
- field
- useFieldArray
- useField
- useWatch
- useFormState
- FormProvider
- useFormContext
- Form
- Submit
- nestValues
- flattenValues
- FormState
- FieldState
- UseFormOptions
- FormValues
- FieldNames
- FieldValue
- NestValues
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.
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.
Built to be used together.
Your form, minus the plumbing. The plumbing was most of it.
bun add @pyreon/form