From https://react-hook-form.com/api/useform/formstate I am using the isValid state to check if input matches the rules
<form> <Controller name="username" control={control} rules={{ minLength: { value: 2, message: 'Tx', }, pattern: { value: /^([A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)/, message: 'x', }, }} render={({ field: { ref, ...field } }) => ( <SecondaryInput name="username" errors={errors} innerRef={ref} {...field} /> )} /> <PrimaryButton disabled={!isDirty || !isValid} type="submit" > Test Submit </PrimaryButton> </form> And it works:
- Button is disabled (empty input)
- I type
- Button not disabled anymore
But when I delete everything (empty input) the button is not disabled. The isValid state remains true
It is probably due to the isDirty state but I don't know how the code works without the isDirty state