Forms and Submit
Handle onSubmit on the form, call preventDefault to stop the page reload and read values from state.
Example
function Login() {
const [email, setEmail] = useState('');
function submit(e) {
e.preventDefault();
console.log(email);
}
return (
<form onSubmit={submit}>
<input value={email} onChange={(e) => setEmail(e.target.value)} />
<button>Send</button>
</form>
);
}Exercise
Stop the reload.
e.()
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.