1.2.27
π Improvements
- π
Improved initializing form values with
initialValues
.
Here's the docs:
By default, formup will already create the form initial values according to your yup schema. This means that any default(...)
will be taken into consideration, and it will always initialize the form as an empty valid object of your schema.
For example, the schema:
const schema = yup.object().shape({
userId: yup
.number()
.default(100),
personalInformation: yup.object().shape({
firstName: yup
.string()
.required(),
email: yup
.string()
.default("[email protected]")
.required(),
}),
});
Will automatically translate to:
{
userId: 100,
personalInformation: {
firstName: "",
email: "[email protected]",
},
}
However, you can customize any value generated within your initial values by passing initialValues
to useFormup
options. Formup will automatically merge the two objects into one, taking your overrides into consideration.
Here's an example, using the schema declared above:
useFormup(schema, {
initialValues: {
userId: 999,
personalInformation: {
firstName: "Foo",
},
},
});
This will produce:
{
userId: 999,
personalInformation: {
firstName: "Foo",
email: "[email protected]",
},
}