0
0
React Nativemobile~5 mins

TextInput with controlled state in React Native - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a controlled TextInput in React Native?
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
Which hook is used to create a state variable for TextInput value?
AuseState
BuseEffect
CuseContext
DuseRef
What prop do you use to detect text changes in a TextInput?
AonTextChange
BonChangeText
ConInput
DonChange
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
Why might you prefer controlled TextInput over uncontrolled?
ATo avoid using state
BTo improve performance
CTo disable keyboard
DTo handle input validation easily
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.