Consider this React Native component with a controlled TextInput. What will the Text below display as you type?
import React, { useState } from 'react'; import { View, TextInput, Text } from 'react-native'; export default function App() { const [text, setText] = useState(''); return ( <View> <TextInput value={text} onChangeText={setText} placeholder="Type here" /> <Text>{text}</Text> </View> ); }
Think about how the value and onChangeText props work together in a controlled input.
Because the TextInput's value is tied to the text state, and onChangeText updates that state, the Text below updates immediately as you type.
Which code snippet correctly updates the state when the user types in a controlled TextInput?
Remember that onChangeText receives the new text string directly, not an event object.
In React Native, onChangeText passes the new text string directly, so the handler should accept that string and update state. Options A and D do this correctly.
In a controlled TextInput, what is the effect of removing the value prop but keeping onChangeText?
import React, { useState } from 'react'; import { TextInput } from 'react-native'; export default function App() { const [text, setText] = useState(''); return <TextInput onChangeText={setText} placeholder="Type here" />; }
Think about controlled vs uncontrolled inputs and what happens when value is missing.
Without the value prop, the TextInput is uncontrolled. It shows user input normally, but since onChangeText updates state, the state changes but does not control the input display.
Given this code, why does the TextInput not show what the user types?
import React, { useState } from 'react'; import { TextInput } from 'react-native'; export default function App() { const [text, setText] = useState(''); return <TextInput value={text} onChangeText={() => setText('')} placeholder="Type here" />; }
Look at what onChangeText does to the state on every input.
The onChangeText handler sets the state to an empty string every time the user types, so the input always shows empty.
Why do developers prefer controlled TextInput components over uncontrolled ones in React Native?
Think about how state and UI stay in sync with controlled inputs.
Controlled inputs let the app manage the input value through state, enabling real-time validation, formatting, and consistent UI updates.