InterviewBuddy
All interview questions

What is the difference between controlled and uncontrolled inputs?

Beginner

Answer

A controlled input gets its current value from React state and reports edits through an event handler. An uncontrolled input keeps its value in the DOM, which you can read through a ref or form submission.

Explanation

Controlled inputs make validation and dependent UI straightforward. Uncontrolled inputs can be simpler when you only need the value on submit. Choose based on the interaction, not a blanket rule.

Example

<input value={name} onChange={e => setName(e.target.value)} />