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
What makes a form input 'controlled' in React?
Answer: Its value is managed by React state
A controlled input's value is bound to React state, making React the single source of truth for the input's value.
How do you prevent a form's default submission behavior in React?
Answer: Call `event.preventDefault()` in the onSubmit handler
Calling event.preventDefault() inside the onSubmit handler stops the browser from performing its default form submission and page reload.
For a checkbox input, which property gives you the boolean checked state in an onChange handler?
Answer: event.target.checked
event.target.checked returns the boolean true/false state of a checkbox, while event.target.value returns the checkbox's value attribute string.
What is the recommended pattern for handling multiple controlled inputs with a single onChange handler?
Answer: Use event.target.name to identify the input and update the corresponding state key
Using event.target.name allows a single onChange handler to update the correct key in a state object, reducing code duplication.
What is an 'uncontrolled' component in React?
Answer: A component where the DOM manages its own form data internally
In uncontrolled components, the DOM itself maintains the form data, and you access it via refs rather than React state.
What does the `defaultValue` prop do on a React input element?
Answer: Sets the initial value without making the input controlled
`defaultValue` sets the initial value for an uncontrolled input without binding it to React state, unlike `value` which creates a controlled component.
Which React event fires when the value of an input, textarea, or select element changes?
Answer: onChange
React's onChange event fires whenever the value of a form element changes, and behaves similarly to the native DOM oninput event.
Written and edited by Nathan Beja, 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