react-hook-form batch async validation

Viewed 301

Say I have 3 separate fields in my form and I want to validate them asynchronously, i.e. by sending a request to the server. Currently, I am doing this manually on the submit handler. I know you can define your custom validate() function for registered controllers, but that would cause 3 separate requests to be performed.

How to batch them together so there is only one request for all three fields?

1 Answers

You have to set mode in useForm to "onSubmit" to make the validation trigger on the submit event.

useForm({
    ...
    mode: "onSubmit"
})

Related