Skip to content
Advertisement

Perform function after form validation

I am using react, typescript, and Email JS library. I am using the react-hook-form library and yup to validate forms.

I have worked out the validation and sending the email, but I am unable to do both these functions together. When a user submits the form, I want the “sendEmail” function to be called if the “handleSubmit(onSubmit)” function which validates the form is successful.

The form’s ‘onSubmit’ property needs to be changed so that both of these can be called. Currently I can call these individually with ‘onSubmit={sendEmail}’ or ‘onSubmit={handleSubmit(onSubmit)}’ and they will work.

What I tried was to put the expression ‘handleSubmit(onSubmit)’ inside the sendEmail function but validation did not work then.

I have also used react-hook-form library.

JavaScript

Advertisement

Answer

As stated in the doc, if you want to call onSumbit remotely you need to write it like this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement