Answer the question
In order to leave comments, you need to log in
Is there any way to check if all required fields are filled in react-hook-form?
I am using the react-hook-form
library .
There is a task - if all the fields are filled in correctly, then I display the component with the button.
There is an errors object , which stores all information about errors.
But there is a problem - when the user enters the page for the first time, it is logical that he has not filled in the fields yet.
And at this time, the errors object is empty because the user hasn't yet triggered onBlur to validate the form.
Question: is there any way to find out if all the required fields in the form are filled in?
If I manually call triggerValidation in useEffect, for example, but errors will appear for fields that the user has not yet filled in.
Answer the question
In order to leave comments, you need to log in
The formState object can help you:
const { isDirty, isValid } = formState;
return <>{isDirty && isValid && <button />}</>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question