Schema

The same sign-up form, validated by eight schema libraries. In each, the inputs hold strings and onSubmit receives the parsed output: the name trimmed, the age a number. See Schema validation.

  • Zod, Valibot, ArkType, Yup (1.7+), Effect Schema implement Standard Schema: pass the schema to the schema prop. No resolver package; onSubmit is typed by the schema output.
  • Ajv (JSON Schema), Joi, Superstruct: pass a resolver from @hookform/resolvers to formOptions.resolver.

Field rules are not used with a schema: all validation, messages included, lives in the schema. The * marker comes from rules.required, so set required: true on a field to show it.

Zod
Valibot
ArkType
Yup
Effect Schema
Ajv
Joi
Superstruct

pnpm add zod. z.coerce.number<string>() keeps the input type a string while the output is a number.

import { useState } from "react";
import { z } from "zod";
import { Form } from "../form.setup";

// The inputs hold strings; the schema trims the name and parses the age
const signupSchema = z.object({
  name: z.string().trim().min(1, "Name is required"),
  email: z.email("Invalid email"),
  age: z.coerce.number<string>().int().min(18, "Must be 18 or older"),
});

export default function SignupForm() {
  const [output, setOutput] = useState<z.output<typeof signupSchema>>();
  return (
    <Form
      schema={signupSchema}
      defaultValues={{ name: "", email: "", age: "" }}
      config={{
        name: { type: "text", label: "Name" },
        email: { type: "text", label: "Email" },
        age: { type: "text", label: "Age", props: { inputMode: "numeric" } },
      }}
      // `data` is the schema output: the name trimmed, the age a number
      onSubmit={(data) => setOutput(data)}
    >
      <button type="submit">Sign up</button>
      {output && <pre data-testid="output">{JSON.stringify(output)}</pre>}
    </Form>
  );
}