Skip to content

v0.6.2

Compare
Choose a tag to compare
@edmundhung edmundhung released this 21 May 22:48
· 353 commits to main since this release

Improvements

  • The useForm hook can now infer the shape directly based on the return type of the onValidate hook (#149)
// e.g. using zod
const schema = z.object({
    title: z.string().min(1, 'Title is required'),
    // ...
})

// Before (Manual typing is needed)
function Example() {
    const [form, fieldset] = useForm<z.infer<typeof schema>>({
        onValidate({ formData }) {
            return parse(formData, { schema });
        }
    })

    console.log(fieldset.title);
    // ^ FieldConfig<string>
}

// After (Directly inferred from the schema)
function Example() {
    const [form, fieldset] = useForm({
        onValidate({ formData }) {
            return parse(formData, { schema });
        }
    })

    console.log(fieldset.title);
    // ^ FieldConfig<string>
}
  • Added support to zod schema intersection when deriving validation attributes with getFieldsetConstraints (#148)
const constraint = getFieldsetConstraint(
    z
    .object({ a: z.string() })
    .and(z.object({ a: z.string().optional(), b: z.string() }))
);
// This generates { a: { required: false }, b: { required: true } }
  • Added union support on both schema and constraint type (#149)
  • The Submission type is slightly adjusted for better accessibility (#149)
  • Fixed a bug which triggers validation when user unfocused a button

New Contributors

Full Changelog: v0.6.1...v0.6.2