React · Junior · Question 19 of 75
How do you cancel the default form submission behavior in React?
- 1Return
falsefrom the form'sonSubmithandler - ✓Correct answer: Call
e.preventDefault()in theonSubmithandler - 3Add a
noSubmitattribute to the<form>tag in JSX
Explanation
In React, handlers receive a synthetic event with the same API as the native one. return false, as in old inline HTML handlers, doesn't work here. You can stop bubbling with e.stopPropagation().