A controlled TextInput is one where the input value is managed by React state. The displayed text is set by a state variable, and changes update that state.
Click to reveal answer
beginner
Why use controlled TextInput instead of uncontrolled?
Controlled TextInput lets you validate, format, or respond to user input immediately by keeping the input value in React state.
Click to reveal answer
beginner
Which React hook is commonly used to manage TextInput state?
The useState hook is used to create a state variable and update function to control the TextInput value.
Click to reveal answer
beginner
How do you update the state when the user types in a controlled TextInput?
You pass a function to the TextInput's onChangeText prop that receives the new text and calls the state update function.
Click to reveal answer
intermediate
What happens if you forget to update the state in a controlled TextInput?
The TextInput will not update its displayed text because the value prop stays the same, making the input appear frozen.
Click to reveal answer
In React Native, which prop sets the displayed text in a controlled TextInput?
Atext
BdefaultValue
Cvalue
Dinput
✗ Incorrect
The value prop controls the displayed text in a controlled TextInput.
Which hook is used to create a state variable for TextInput value?
AuseState
BuseEffect
CuseContext
DuseRef
✗ Incorrect
useState creates state variables and update functions.
What prop do you use to detect text changes in a TextInput?
AonTextChange
BonChangeText
ConInput
DonChange
✗ Incorrect
onChangeText is the correct prop for text change events in React Native TextInput.
What happens if you set a fixed value prop but do not update state on text change?
ATextInput becomes read-only
BTextInput clears text
CTextInput crashes
DTextInput updates normally
✗ Incorrect
Without updating state, the TextInput appears read-only because value never changes.
Why might you prefer controlled TextInput over uncontrolled?
ATo avoid using state
BTo improve performance
CTo disable keyboard
DTo handle input validation easily
✗ Incorrect
Controlled inputs let you validate or format input as the user types.
Explain how to create a controlled TextInput in React Native.
Think about how React state controls the input text.
You got /4 concepts.
Describe what happens if the onChangeText handler does not update the state in a controlled TextInput.
Consider the connection between state and displayed text.
You got /3 concepts.
Practice
(1/5)
1. What does it mean when a TextInput in React Native is "controlled"?
easy
A. The input value is managed by React state using value and onChangeText.
B. The input automatically saves data to a database.
C. The input cannot be edited by the user.
D. The input uses default native keyboard settings only.
Solution
Step 1: Understand controlled input concept
A controlled TextInput means React state holds the current text value.
Step 2: Identify how React manages input
React uses value prop to set input text and onChangeText to update state on typing.
Final Answer:
The input value is managed by React state using value and onChangeText. -> Option A
Quick Check:
Controlled input = React state control [OK]
Hint: Controlled means React state controls input text [OK]
Common Mistakes:
Thinking controlled means input is read-only
Confusing controlled with auto-saving
Assuming native keyboard controls the value
2. Which of the following is the correct way to create a controlled TextInput in React Native?
easy
A. <TextInput value={text} onChange={setText} />
B. <TextInput value={text} onChangeText={setText} />
C. <TextInput defaultValue={text} onChange={setText} />
D. <TextInput defaultValue={text} onChangeText={text} />
Solution
Step 1: Identify correct props for controlled input
The value prop sets the input text, and onChangeText updates state on typing.
Step 2: Check each option's syntax
<TextInput value={text} onChangeText={setText} /> uses value and onChangeText correctly. Others misuse onChange or defaultValue.
Final Answer:
<TextInput value={text} onChangeText={setText} /> -> Option B
Quick Check:
Use value + onChangeText for controlled input [OK]
Hint: Use value and onChangeText props for controlled TextInput [OK]
Common Mistakes:
Using onChange instead of onChangeText
Using defaultValue for controlled input
Passing wrong handler to onChangeText
3. What will be displayed inside the TextInput after typing "Hi" in this code?