A controlled input in React means…
Options
- The DOM holds the value, which is read with a ref
- React state is the truth, via
valueandonChange(Correct option) - The input is disabled so users cannot type in it
- The value is kept in the browser's localStorage
Answer
React state is the single source of truth via value + onChange
Why
In a controlled input, React state holds the value: <input value={name} onChange={e => setName(e.target.value)} />. Every keystroke updates state, and state decides what is shown.
This lets you validate or format as the user types.
An uncontrolled input keeps its own value in the DOM and you read it with a ref when needed.
const [name, setName] = useState("");
<input value={name} onChange={e => setName(e.target.value)} />Remember
Controlled = React state drives the input.