Default values

Setting default values in RVF is easy using the defaultValues option in the useForm hook.

const form = useForm({
  // ...validator and other options
  defaultValues: {
    firstName: "Jane",
    lastName: "Doe",
    email: "jane.doe@example.com",
  },
});

Type safety

For most forms, it's recommended to always set default values. The types of the form object returned by useForm (form.value(), form.setValue(), etc) are based entirely around the type you define for the default values. In some cases, this may mean you need to specify the type of a value for values that can be more than one type.

const form = useForm({
  // ...validator and other options
  defaultValues: {
    selectedOption: null as string | null,
  },
});

Example

Form with default values

Create an account