v0.6.2
Improvements
- The
useForm
hook can now infer the shape directly based on the return type of theonValidate
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
- @ollie-bud made their first contribution in #139
Full Changelog: v0.6.1...v0.6.2