Controlled and Uncontrolled are two approaches to working with forms in React.
Simple analogy: Imagine you are ordering pizza by phone.
Controlled (through state):
1function Form() {2 const [name, setName] = useState('');34 return (5 <input6 value={name} // Value from state7 onChange={e => setName(e.target.value)} // Update state8 />9 );10}
React fully controls the value. Every character input → setState → re-render. Pros: easy to validate, easy to submit form, easy to reset.
Uncontrolled (through ref):
1function Form() {2 const inputRef = useRef();34 function handleSubmit() {5 alert(inputRef.current.value); // Read from DOM directly6 }78 return (9 <input ref={inputRef} defaultValue="" />10 );11}
Value is stored in DOM. React does not control it (defaultValue is only for initial value). Pros: fewer re-renders, simpler for simple forms.
When to use what:
Performance consideration: Controlled components re-render on every keystroke. For forms with many inputs, this can be noticeable. Uncontrolled components avoid this since values live in the DOM.
Common mistake: Forgetting e.preventDefault() in onSubmit handler for controlled forms, which causes a full page reload.