React Native

React Native – Text Input

The most basic use case is to plop down a TextInput and subscribe to the onChangeText events to read the user input.

Inputs allow users to enter text into a UI. They typically appear in forms and dialogs. It has an onChangeText prop which requires a function that will be called every time when the text changes, and it also has a value prop that can set a default value into it.

To Import TextInput in the Code
import { TextInput } from 'react-native'
Render Using
<TextInput placeholder = "Email" onChangeText = {this.state.email}/>
Props
allowFontScalingautoCapitalizeautoCorrectautoFocus
blurOnSubmitcaretHiddenclearButtonModeclearTextOnFocus
contextMenuHiddendataDetectorTypesdefaultValuedisableFullscreenUI
editableenablesReturnKeyAutomaticallyinlineImageLeftinlineImagePadding
keyboardAppearancekeyboardTypemaxLengthmultiline
numberOfLinesonBluronChangeonChangeText
onContentSizeChangeonEndEditingonFocusonKeyPress
onLayoutonScrollonSelectionChangeonSubmitEditing
placeholderplaceholderTextColorreturnKeyLabelreturnKeyType
scrollEnabledsecureTextEntryselectionselectionColor
selectionColorselectionStateselectTextOnFocusspellCheck
textContentTypestyletextBreakStrategyunderlineColorAndroid
import React from 'react';
import { TextInput, View, StyleSheet, Text } from 'react-native';
export default class App extends React.Component {
 constructor(props) {
   super(props);
   this.state = {
     username: ''
   };
 }
 render() {
   return (
     <View style={styles.container}>
       <Text style={{color: 'black'}}>{this.state.username}</Text>
       <TextInput
         value={this.state.username}
         onChangeText={(username) => this.setState({ username })}
         placeholder={'Username'}
         style={styles.input}
       />
     </View>
   );
 }
}
const styles = StyleSheet.create({
 container: {
   flex: 1,
   alignItems: 'center',
   justifyContent: 'center',
   backgroundColor: '#ffffff',
 },
 input: {
   width: 250,
   height: 44,
   padding: 10,
   marginBottom: 10,
   backgroundColor: '#ecf0f1'
 },
});
Text Input

We can also use multiline prop by making it true.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button