Tsallaka zuwa abun ciki
Justice Tech School

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

What does preventDefault stop?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.