React TutorialLesson 30Free preview
React Forms Submit
This lesson is part of React · All levels
Summary
HTML forms are inherently refreshing pages when submitted, so React uses an onSubmit event that calls e.preventDefault(). After that prevention, the data from the state can be read, validated, then sent to the server or displayed. This pattern keeps the app running as a single page.
Key points
- Insert the handler on the attribute onSubmit form element
- Call e.preventDefault() so that the page does not reload
- Read the grade from the state, not from the DOM directly.
- Validate data before processing or sending it
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.