You know, an app becomes more authentic and professional when there is the interaction between the app and the user.
您知道,當應用程序與用戶之間存在交互時,該應用程序將變得更加真實和專業。
The text input component in react-native brings that interaction between the application and the users by allowing the text to be input by the users using the keyboard.
react-native中的文本輸入組件通過允許用戶使用鍵盤輸入文本,從而在應用程序和用戶之間帶來了交互。
You will surely find some differences with that of React JS.
您一定會發現與React JS有所不同。
The text input component has some attributes like onChangeText and onSubmitEditing which make text input fascinating and more interactive.
文本輸入組件具有一些屬性,例如onChangeText和onSubmitEditing ,這些屬性使文本輸入引人入勝并且更具交互性。
Text input is like a self-closing tag and is written as a word. Below is a brief example.
文本輸入就像一個自動關閉標簽,被寫成一個單詞。 下面是一個簡短的示例。
Open your App's App.js file and type the following,
打開您應用的App.js文件,然后輸入以下內容,
import * as React from 'react';
import {useState} from 'react';
import { Text, View, StyleSheet, Button, TextInput } from 'react-native';
export default function App () {
return (
<View style={styles.container}>
<Text> I love JESUS</Text>
<TextInput
placeholder='type your message here'
autoCapitalize = "characters"
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
From the code above, we begin by importing the component from react native before being able to use it else, an error will occur.From the code above, we begin by importing the component from react native before being able to use it else, an error will occur.
從上面的代碼開始,我們先從react native導入組件,然后才能使用其他組件,然后會發生錯誤。從上面的代碼開始,我們首先要從react native導入組件,然后再使用其他組件。將會發生錯誤。
I have also implemented the placeholder attribute which works here just like in html and the autoCapitalize property which simply converts every text input to capital letters. Other attributes and props can be seen on the official documentation.
我還實現了占位符屬性,該屬性在這里像html一樣工作,而autoCapitalize屬性僅將輸入的每個文本轉換為大寫字母。 其他屬性和道具可以在官方文檔中找到。
Take Note: Auto Capitalize doesn't work from all keyboards.
請注意:并非所有鍵盤都支持自動大寫。
Output
輸出量
Thanks for coding with me! See you @ the next article. Feel free to drop a comment or question. God Bless You!
感謝您與我編碼! 下次見。 隨意發表評論或問題。 上帝祝福你!
翻譯自: https://www.includehelp.com/react-js/how-to-use-text-input-component-in-react-native.aspx