Handling text input in React Native involves using the TextInput
component provided by React Native. You can capture the value entered by the user and use it for various purposes like form submissions, search functionalities, etc.
import React, { useState } from 'react';
import { View, TextInput, Button, Alert } from 'react-native';
const TextInputExample = () => {
const [textInputValue, setTextInputValue] = useState('');
const handleTextInputChange = (text) => {
setTextInputValue(text);
};
const handleSubmit = () => {
Alert.alert('Entered Text', textInputValue);
};
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TextInput
style={{ height: 40, width: 200, borderColor: 'gray', borderWidth: 1, padding: 10 }}
placeholder="Enter text..."
onChangeText={handleTextInputChange}
value={textInputValue}
/>
<Button title="Submit" onPress={handleSubmit} />
</View>
);
};
export default TextInputExample;
© www.thecoderjob.com. All Rights Reserved. Designed by HTML Codex