0
0
Reactframework~5 mins

Controlled components in React - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a controlled component in React?
A controlled component is a form element (like input, textarea, select) whose value is controlled by React state. The component's displayed value is set by React, and user input updates the state.
Click to reveal answer
beginner
How do you update the value of a controlled input in React?
You update the value by changing the state that controls the input's value, usually inside an event handler like onChange.
Click to reveal answer
intermediate
Why are controlled components preferred over uncontrolled components in React?
Controlled components keep React as the single source of truth for form data, making it easier to validate, modify, or submit form data and keep UI consistent.
Click to reveal answer
intermediate
What happens if you do not provide an onChange handler to a controlled input?
The input becomes read-only because React controls its value but has no way to update it from user input.
Click to reveal answer
beginner
Show a simple React controlled input example.
Example: <br>const [name, setName] = React.useState('');<br><input value={name} onChange={e => setName(e.target.value)} />
Click to reveal answer
In React, what controls the value of a controlled input?
AReact state
BThe DOM directly
CBrowser default behavior
DCSS styles
What must you provide to a controlled input to allow user typing?
AA defaultValue attribute
BA ref to the input element
CAn onChange handler that updates state
DA CSS class
Which is a benefit of controlled components?
AReact manages form data centrally
BThey require less code than uncontrolled components
CThey automatically validate input
DThey do not need event handlers
What happens if you set a controlled input's value but omit onChange?
AReact throws an error
BInput updates normally
CInput clears automatically
DInput becomes read-only
Which React hook is commonly used to create controlled components?
AuseEffect
BuseState
CuseRef
DuseContext
Explain what a controlled component is and why it is useful in React forms.
Think about who controls the input's value and how React uses state.
You got /3 concepts.
    Describe how you would implement a controlled text input in React.
    Remember the flow: user types → onChange → update state → input value updates
    You got /3 concepts.