Web Development
React.js
Subjective
Sep 28, 2025
What are controlled and uncontrolled components?
Detailed Explanation
Controlled components have their form data handled by React state. Uncontrolled components store form data in the DOM itself.
// Controlled component
function ControlledInput() {
const [value, setValue] = useState("");
return (
<input
value={value}
onChange={e => setValue(e.target.value)}
/>
);
}
// Uncontrolled component
function UncontrolledInput() {
const inputRef = useRef();
return <input ref={inputRef} />;
}Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts