Skip to main content
PProfileMatch
← Path

React · React Events and Forms: Controlled Inputs

0 XP
  1. 1 current stop: learning
  2. 2 upcoming
  3. 3 upcoming
  4. 4 upcoming
  5. 5 upcoming

Finish after stop 5

Stop 1 of 5 · Post office: the stamped envelope

Trick to keep in mind+3 XP

A default submit is a trip to a new page; preventDefault cancels the trip.

By default the browser handles a form submit itself: it sends a request and loads a fresh page, which throws away everything React was holding in memory. Your onSubmit handler still runs, but the damage comes from the default action that happens next. The event object offers a way to cancel that default action.

Read it once, then a question tests whether the trick stuck.