2
votes

I'm checking this example in react-hook-form doc: https://codesandbox.io/s/react-hook-form-v6-controller-qsd8r?file=/src/index.js

Weird thing is that the button doesn't have type="submit". But it still triggers submit event after clicking.

How does it know which button is the submit button?

1
As a side node: if multiple <button> elements are left without either type="submit" or "type="button", the latter will always be placed by default no-matter-what, so you'll have multiple buttons being able to submit the form. type="button" strips the submit ability.Constantin

1 Answers

6
votes

If a button is inside a form, then by default it is given the submit type, unless you give it another type.

So the Reset button in that codesandbox has type="button" to prevent it triggering the event, but the Submit button leaves it blank, so it submits by default.

Reference: Moz Docs