Skip to content
Advertisement

React – Unhandled Rejection (TypeError): e.preventDefault is not a function

I’m getting this error below when I try to implement an Axios post with react-hook-form:

JavaScript

The problem started occuring when I added onSubmit={handleSubmit(handleSubmitAxios)} to my <form>. Basically, I want my form to be controlled by react-hook-form, using my custom handleSubmitAxios post call that communicates with my backend.

This is for my sign-in component, currently just testing out the functionality of react-hook-form however the e.preventDefault message is confusing me.

JavaScript

Thank you for any help or guidance on how I can solve the original error!

Advertisement

Answer

As per the docs, First parameter is the data or errors object, second parameter is the form event.

((data: Object, e?: Event) => void, (errors: Object, e?: Event) => void) => Function

In your case is e is the data, that’s why you’re getting e.preventDefault is not a function error.

Try like this

JavaScript

But, The react-hook-form is already preventing the default form event, Not sure why you wanna do that again. Check this screen shot once and demo too

enter image description here

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