Web Development
React.js
Subjective
Sep 25, 2025
What is the difference between controlled and uncontrolled components?
Detailed Explanation
Controlled components: Form data handled by React state\nUncontrolled components: Form data handled by DOM\n\nControlled example:\nfunction ControlledInput() {\n const [value, setValue] = useState("");\n \n return (\n setValue(e.target.value)} \n />\n );\n}\n\nUncontrolled example:\nfunction UncontrolledInput() {\n const inputRef = useRef();\n \n const handleSubmit = () => {\n console.log(inputRef.current.value);\n };\n \n return ;\n}\n\nControlled components are preferred for validation and dynamic behavior.
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts