Controlled Input
Question
What is a controlled component in React forms?
Hint
Controlled inputs have value and onChange driven by state.
Explanation
A controlled component is a form input whose value is controlled by React state. The input value is set from state, and onChange updates the state: <input value={text} onChange={e => setText(e.target.value)} />. This gives React full control over the input, enabling validation, formatting, and conditional behavior. The alternative is an uncontrolled component using defaultValue and refs. Controlled components are the recommended pattern in React.
Related Resources
Related Lessons
- Forms
Learn forms.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.