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?

  1. 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
  2. B.A controlled component cannot have a default value, while an uncontrolled component always requires one
  3. C.Controlled components only work with class components, and uncontrolled components only work with function components
  4. 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

All of Interview Questions

Practise more ReactJs

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed