v7.1.0 -- Standard Schema support
Overview
The main addition for this release is support for Standard Schema. π We've also stabalized the useNativeValidityForForm
api.
Standard Schema
It's now possible to directly pass zod
, valibot
, or any other Standard Schema compliant schema into the useForm
hook or ValidatedForm
component. To do this, you need to use the new schema
option.
useForm({
schema: z.object({ /* etc */ }),
})
Some other new features around this are:
Default values are now required
When using a Standard Schema schema, the defaultValues
option is required. It remains optional if you're still using a validator
.
Type inference for default values
Standard Schema allows schemas to define an input type for the schema. This is used to infer the type of default values, but it's still possible to widen this type if you need.
useForm({
schema: z.object({
myNumber: z.number(),
myOtherNumber: z.number(),
}),
defaultValues: {
// This still works!
myNumber: null as null | number,
// But this fails
myOtherNumber: null,
}
})
Zod and Valibot adapters deprecated
Zod and Valibot both support Standard Schema, so they are automatically supported by the schema
prop.
Therefore, the withZod
and withValibot
adapters are now deprecated.
Future direction
I'm planning on eventually removing the validator
prop in favor of schema
. The official Yup adapter will eventually be reworked to wrap the Yup schema to make it Standard Schema compliant, rather than using a custom Validator object.
useNativeValidityForForm
This was an unstable API that's now been stabilized with this release. Read the docs here.
Auto release notes:
What's Changed
- Update
.npmignore
by @darthmaim in #409 - Adding viewTransition to the useForm by @ZipBrandon in #412
- fix typo by @sajadtorkamani in #428
- Standard schema support by @airjp73 in #431
New Contributors
- @darthmaim made their first contribution in #409
- @sajadtorkamani made their first contribution in #428
Full Changelog: v7...rvf-7.1.0