L
L
lexstile2020-10-01 10:29:48
React
lexstile, 2020-10-01 10:29:48

How to prevent form submit on hitting enter in react hook form?

I try like this:

<form
          className={s.modal__form}
          onSubmit={(e) => {
            e.preventDefault();

            methods.handleSubmit(onSubmit)(e); <!-- Если я не передаю сюда событие, форма вовсе не отправляется, если передаю, prevent не работает -->
          }}
        >

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Didenko, 2020-10-01
@lexstile

Perhaps e.preventDefault needs to be called in the keydown handler on the enter key?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question