Rara writes tonight’s puppet on the name board on the neighbourhood head’s screen: a controlled input, an uncontrolled one with a ref, or value with no…
Why it matters
Every React form uses one of them. Misreading it breeds the classic bugs: a "frozen" input (value with no onChange), the controlled/uncontrolled warning, a form reset that clears nothing, or a Save that prints an empty text.
The key idea
Controlled: React holds the text. Uncontrolled: the DOM does
Common mistakes
value with no onChange The input turns read-only (frozen) and React warns. Add onChange, or use defaultValue if it is meant to be uncontrolled.
Switching from uncontrolled to controlled Switching from defaultValue (or value={undefined}) to value after mount triggers a warning. Pick one mode and keep to it.
value={undefined} and then a string Undefined at first = uncontrolled, then it turns controlled. Start the state at '', not undefined.
Try it in this playground
Type with a capitals onChange Rara types 'semar', it shows 'SEMAR': what renders is the state.
value with no onChange Rara types, the input stays: React puts the value back.
Clear an uncontrolled input setNama('') never touches the text the DOM holds.
useState() and then type From undefined to a string: the input switches to controlled.