Component - TextInput component
The TextInput component lets users type text into the app. It is like a blank box where you can enter words, numbers, or other characters. This is useful for forms, search bars, or any place you want user input.
The TextInput component lets users type text into the app. It is like a blank box where you can enter words, numbers, or other characters. This is useful for forms, search bars, or any place you want user input.
View └── TextInput
TextInput component in React Native?TextInput?onChangeText.setText(text).const [text, setText] = React.useState('Hello');
return (
<TextInput
value={text}
onChangeText={setText}
placeholder="Type here"
/>
);text is initialized with 'Hello', so the input shows this text.const [input, setInput] = React.useState('');
return (
<TextInput
value={input}
onChange={(text) => setInput(text)}
/>
);onChangeText to handle text changes, not onChange.value prop is present and state usage is correct.TextInput that clears its text when the user submits. Which approach is correct?const [text, setText] = React.useState('');
return (
<TextInput
value={text}
onChangeText={setText}
onSubmitEditing={() => setText('')}
placeholder="Enter text"
/>
);text state and updated by onChangeText.onSubmitEditing callback sets the text state to empty string, clearing the input on submit.Pass the test and this pattern moves unknown