What is the purpose of the <TextInput> component in React Native?
The <TextInput> component allows users to enter and edit text in a React Native app, similar to a text box in web forms.
Click to reveal answer
beginner
How do you capture the text entered by a user in a <TextInput>?
You use the onChangeText prop to provide a function that receives the current text value whenever it changes.
Click to reveal answer
beginner
Which prop controls the placeholder text shown inside a <TextInput> before the user types?
The placeholder prop sets the light text shown inside the input when it is empty, guiding the user what to enter.
Click to reveal answer
intermediate
How can you make a <TextInput> secure for entering passwords?
Set the secureTextEntry prop to true to hide the text input, showing dots or asterisks instead of the actual characters.
Click to reveal answer
intermediate
What is the difference between controlled and uncontrolled <TextInput> components?
A controlled <TextInput> has its value managed by React state via the value prop, while an uncontrolled one manages its own internal state without React controlling it.
Click to reveal answer
Which prop do you use to update React state when the user types in a <TextInput>?
Avalue
BonChangeText
Cplaceholder
DsecureTextEntry
✗ Incorrect
The onChangeText prop is a function called with the new text whenever the user types.
How do you show a hint inside a <TextInput> before the user types?
Aplaceholder
BdefaultValue
ChintText
Dlabel
✗ Incorrect
The placeholder prop displays light text inside the input as a hint.
What prop makes a <TextInput> hide the entered text for passwords?
AsecureTextEntry
Bpassword
Chidden
DmaskText
✗ Incorrect
secureTextEntry=true hides the text input for password fields.
Which prop sets the current text shown inside a controlled <TextInput>?
Atext
Bcontent
Cvalue
DdefaultValue
✗ Incorrect
The value prop controls the text shown in a controlled .
What happens if you omit the onChangeText prop in a controlled <TextInput>?
AThe input shows placeholder text
BThe input clears automatically
CThe input crashes the app
DThe input becomes read-only
✗ Incorrect
Without onChangeText updating state, the controlled input cannot change and acts read-only.
Explain how to create a controlled in React Native and why it is useful.
Think about how React state keeps the input text in sync.
You got /4 concepts.
Describe how to make a password input field using and what prop you need.
It’s a simple boolean prop that changes how text is displayed.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the TextInput component in React Native?
easy
A. To display images
B. To create buttons
C. To let users type text in the app
D. To navigate between screens
Solution
Step 1: Understand the role of TextInput
The TextInput component is designed to allow users to enter text data in the app interface.
Step 2: Compare with other components
Other options like displaying images or creating buttons are done by different components, not TextInput.
Final Answer:
To let users type text in the app -> Option C
Quick Check:
TextInput = user text entry [OK]
Hint: TextInput is for typing text only [OK]
Common Mistakes:
Confusing TextInput with Image or Button components
Thinking TextInput handles navigation
Assuming TextInput displays static content
2. Which of the following is the correct way to update the text state when using TextInput?
easy
A. setText(text)} value={text} />
B. setText(text)} value={text} />
C. setText(text)} value={text} />
D. setText(text)} />
Solution
Step 1: Identify the correct event prop for text change
The correct prop to handle text changes in TextInput is onChangeText.
Step 2: Check the syntax for updating state
The function should receive the new text and call the state setter like setText(text).
Final Answer:
<TextInput onChangeText={(text) => setText(text)} value={text} /> -> Option A
Quick Check:
Use onChangeText to update state [OK]
Hint: Use onChangeText, not onChange or others [OK]
Common Mistakes:
Using onChange instead of onChangeText
Using wrong prop names like onTextChange
Not passing the text parameter correctly
3. What will be displayed when the following code runs?