Interview Questions · ReactJs ReactJs
What distinguishes a controlled component from an uncontrolled component in React forms?
Practice question from Interview Questions (ReactJs ReactJs), with the correct answer and a step-by-step solution.
medium · MCQ · Q-4A4020
What distinguishes a controlled component from an uncontrolled component in React forms?
- A.A controlled component stores its current value in React state and updates it via an onChange handler; an uncontrolled component keeps its value in the DOM itself, accessed via a refCorrect answer
- B.A controlled component cannot have a default value, while an uncontrolled component always requires one
- C.Controlled components only work with class components, and uncontrolled components only work with function components
- D.Uncontrolled components cannot be validated, while controlled components are validated automatically by React
Solution
Ask where the 'source of truth' for the input's current value lives: in a React state variable, or in the DOM node itself.
More from Interview Questions
- What is a Higher-Order Component (HOC) in React?
- In a function component, which useEffect dependency-array configuration most closely mirrors the behavior of componentDidMount from class c…
- Why does React use a Virtual DOM instead of directly manipulating the real DOM on every update?
- What problem does the React Context API primarily solve?
Practise more ReactJs
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed