L
L
lexstile2020-12-30 15:49:06
React
lexstile, 2020-12-30 15:49:06

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

1 answer(s)
D
Demian Smith, 2020-12-30
@lexstile

The formState object can help you:

const { isDirty, isValid } = formState;
return <>{isDirty && isValid && <button />}</>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question