Majed Badawi
Majed Badawi

Reputation: 28414

React Hook Form: isDirty not working on load

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.

Upvotes: 6

Views: 4603

Answers (1)

Majed Badawi
Majed Badawi

Reputation: 28414

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

Upvotes: 5

Related Questions