โ† All React Flashcard Decks

Forms and Events Flashcards

7 cards from real React practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Forms and Events flashcards as text
  1. Why must file inputs in React be handled as uncontrolled components?

    Answer: File input values are read-only and cannot be set programmatically

    File input values are read-only by browsers for security reasons, so you cannot set their value via state; instead, you access the selected file via a ref.

  2. Which library is most commonly used for form state management and validation in React?

    Answer: Formik

    Formik is one of the most popular React form libraries, providing utilities for handling form state, validation, and submission with minimal boilerplate.

  3. What is the main performance advantage of React Hook Form over Formik?

    Answer: It uses uncontrolled inputs by default, minimizing re-renders

    React Hook Form uses uncontrolled inputs and refs by default, so changing a field value does not trigger a full component re-render, unlike controlled-input approaches.

  4. When handling form submission with an async API call, what is the correct pattern in React?

    Answer: Call event.preventDefault() and use async/await in the handler

    Calling event.preventDefault() stops page reload while async/await in the handler manages asynchronous API calls cleanly inside the onSubmit function.

  5. What does the `autoComplete` prop on a React input element control?

    Answer: Whether the browser offers autofill suggestions for the field

    The autoComplete prop maps to the HTML autocomplete attribute, instructing the browser whether to offer saved autofill suggestions for that field.

  6. How can you reset all fields of a controlled form in React after submission?

    Answer: Set each state value back to its initial empty value

    Since controlled inputs derive their values from state, resetting the form means setting each piece of state back to its initial empty value (e.g., empty string).

  7. What is the correct way to imperatively focus a specific input field in React after a form error?

    Answer: Attach a ref to the input and call ref.current.focus() in a useEffect

    Attaching a ref to the target input and calling ref.current.focus() inside a useEffect that runs when the error appears is the idiomatic React way to programmatically focus an element.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy