Reputation: 28414
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
Reputation: 28414
The issue was that I was not passing the defaultValues
of the form elements.
Upvotes: 5