React Hook Form: isDirty not working on load

Viewed 1506

I'm using react-hook-form to control and validate a form with one required input.

const {control, handleSubmit, formState, reset} = useForm({
  mode: 'onChange',
});
const {isDirty, isValid, errors} = formState;

To disable the submit button:

disabled={!isDirty || !isValid}

The issue is that initially, the submit button is not disabled even if the input is empty.

1 Answers

The issue was that I was not passing the defaultValues of the form elements. enter image description here

Related