Capítulo 98 de 116
<input><input> is the canonical example of React's controlled vs. uncontrolled distinction: pass value + onChange and React owns the field's value (controlled); pass defaultValue and let the DOM manage it internally, reading it via a ref only when needed (uncontrolled) — mixing the two on the same input is an error.
<input value={text} onChange={e => setText(e.target.value)} /> — the displayed value is always exactly text; every keystroke goes through React state, letting you validate, transform, or restrict input in real time.<input defaultValue={initialText} ref={inputRef} /> — the DOM manages the value itself after the initial render; React only reads it on demand via the ref (e.g. at form submission time via FormData, Ch 97).value and defaultValue — React warns, since they express contradictory ownership models for the same field.onChange handler is read-only and logs a warning — passing value alone (no way to update it) traps the field at its initial value, which is almost never intended.checked/defaultChecked instead of value/defaultValue, following the same controlled/uncontrolled split.<input type="number">'s value is still a string in e.target.value — convert explicitly (Number(e.target.value)) rather than assuming a numeric type.// Controlled: React state is the single source of truth
<input value={query} onChange={e => setQuery(e.target.value)} />
setQuery, so query always reflects exactly what's displayed.value and defaultValue on the same element.onChange, or it becomes effectively frozen/read-only.e.target.value is always a string, regardless of type — numeric inputs still need explicit conversion.value/onChange.<form>): how uncontrolled field values get read via FormData at submission.