Problem Statement
What are controlled and uncontrolled components in React?
Explanation
In controlled components, form data is handled by React state. In uncontrolled components, the DOM itself manages the input value using refs. Controlled components provide better validation and consistency.
Code Solution
SolutionRead Only
// Controlled
<input value={text} onChange={(e) => setText(e.target.value)} />
// Uncontrolled
<input ref={inputRef} />