Form Submit — Complete Guide
Form Submit — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of React.js Tutorial on Toolliyo Academy.
On this page
React.js Tutorial · Lesson 19 of 100
Form Submit
Beginner → Intermediate → Advanced → Professional
Beginner · 1 — Learn by example · ~6 min · Module 2: Props, Events & Lists
What is this?
Form submit in React uses onSubmit on the
Why should you care?
Login, signup, and checkout all submit without a full page refresh — that is standard SPA behavior.
See it live — copy this example
Paste into src/App.jsx (or the file noted in the steps). Save and watch the browser update.
import { useState } from 'react';
function LoginForm() {
const [email, setEmail] = useState('');
function handleSubmit(e) {
e.preventDefault();
console.log('Login with', email);
}
return (
<form onSubmit={handleSubmit}>
<input value={email} onChange={e => setEmail(e.target.value)} />
<button type="submit">Login</button>
</form>
);
}
Run Example »
Edit the code and click Run to see the result update live.
Code
Result
What happened?
- onSubmit fires when user clicks submit or presses Enter.
- preventDefault stops navigation.
- Read state variables you built with onChange.
Try it yourself
- Wire onSubmit with preventDefault.
- console.log state on submit.
- Add alert(JSON.stringify(formData)) to see all fields.
- Change text or labels in the example and save — watch the browser update.
- Break the code on purpose (remove a bracket), read the error message, then fix it.
Remember
onSubmit + preventDefault on forms. Controlled inputs hold values in state. Submit handler reads state, calls API.