Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  98] [ 3]  / answers: 1 / hits: 6255  / 7 Years ago, thu, march 30, 2017, 12:00:00

I'm confused after reading the documentation for both react and some HTML stuff about how on click event handling should work.



For buttons, for example a button that onClick will dispatch an action to submit a form, is a preventDefault necessary?



Thanks


More From » html

 Answers
17

The event.preventDefault() method stops the default action of an element from happening.



In your case, prevent a submit button from submitting a form.
Another example - prevent a link from following the URL.



So it is preferred to use it on onClick method. It'll stop a form from automatically submitting the form.


[#21779] Tuesday, March 28, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shantelc

Total Points: 737
Total Questions: 120
Total Answers: 104

Location: Nicaragua
Member since Tue, Dec 8, 2020
4 Years ago
;