0
Challenge · 18React Core
Controlled Components
Coreused in ~95% of apps
Make React the single source of truth for every input — the default, and the key to easy validation.
Core idea. A controlled input's value comes from state (value={x}) and updates state on change (onChange), so React always knows and owns the field's value.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
<input value={text} onChange={e => setText(e.target.value)} />
REACT'S STATE
"Aria"
4 charsARIA
keystrokesetState(v)value={state}
<input>
you typeonChange(e)
setState(v)
state: "Aria"
React owns itvalue
Type below — watch the value travel the loop and back into the input.
The input never stores its own text — React holds it in state, then hands it back through value. That round-trip is what "controlled" means.
↑ play a little first, then dig in