QuizzesControlled and Uncontrolled Inputs — Concept Check
intermediate
react

Controlled and Uncontrolled Inputs — Concept Check

Questions on Controlled and Uncontrolled Inputs. A controlled input renders from state and updates it on every keystroke. An uncontrolled input keeps its own value in the DOM. Mixing them produces React's most familiar warning.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Controlled and Uncontrolled Inputs — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.You have a form with an email input that uses React state to manage its value. What is a primary advantage of this controlled input approach?

    • AThe input value is stored directly in the DOM.
    • BIt requires less code and fewer renders.
    • CYou cannot disable the submit button.
    • DYou can validate the input as the user types.
  2. 2.In a large form with many fields, which approach is generally preferred for better performance?

    • AControlled inputs to ensure state consistency.
    • BControlled inputs to validate each field.
    • CUncontrolled inputs to reduce re-renders.
    • DUncontrolled inputs to allow real-time validation.
  3. 3.A developer receives a warning: "A component is changing an uncontrolled input to be controlled." What is a likely cause?

    • AThe input is not wrapped in a form element.
    • BThe input is missing an onChange handler.
    • CThe input uses defaultValue instead of value.
    • DThe input starts with an undefined value.
  4. 4.Why might a developer choose to use uncontrolled inputs in a React form?

    • ATo ensure inputs are always controlled by state.
    • BTo allow real-time validation of input data.
    • CTo make it easier to disable form submissions.
    • DTo simplify the code and reduce re-renders.
  5. 5.In a React component, an input field is initially set with `defaultValue`. What does this imply about the input's behavior?

    • AThe input cannot be used in forms with file inputs.
    • BThe input's initial value is set, but it won't re-render on changes.
    • CThe input will update its value on every keystroke.
    • DThe input's value is controlled by the component's state.
  6. 6.A developer wants to ensure an input field only accepts digits and limits to six characters. Which approach should they use?

    • AUncontrolled input with defaultValue set.
    • BControlled input with validation logic in onChange.
    • CUncontrolled input with validation logic in onSubmit.
    • DControlled input with defaultValue set.
  7. 7.What is a potential drawback of using controlled inputs in a large form?

    • AIncreased complexity due to state management.
    • BLack of control over input values.
    • CInability to validate inputs in real-time.
    • DDifficulty in reading input values when needed.
  8. 8.In React, what problem arises when an input field's value is set to null?

    • AThe input's value is not displayed correctly.
    • BThe input requires an additional onChange handler.
    • CThe input cannot accept any user input.
    • DThe input becomes uncontrolled, causing warnings.