问题
Couldn't find a solution.
I'm using react-hook-form
and I want to disable the submit button when the forms are empty and enable as long as all forms have atleast something written in them.
How would I do that using react-hook-form
?
回答1:
you can use formState
=> isDirty
which means form is been modified.
https://react-hook-form.com/api#formState
here is a working example for formState
below:
https://codesandbox.io/s/react-hook-form-v6-formstate-ht098?file=/src/index.jsx:423-432
<input disable={formState.isDirty} type="submit" />
来源:https://stackoverflow.com/questions/65255298/how-to-conditionally-disable-the-submit-button-with-react-hook-form