Skip to content

1.2.27

Compare
Choose a tag to compare
@pedro-lb pedro-lb released this 03 Jun 21:35
· 198 commits to master since this release

πŸ’… 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]",
  },
}