所以到目前為止,這個應用程式上有很多 TextInputs,但這是其中唯一一個不允許任何文本的,它只是閃爍輸入的字母或數字,然后立即洗掉。知道這里可能有什么問題嗎?
MyProfile.js
import { View, Text, StyleSheet, ScrollView, Pressable, TextInput}
from 'react-native'
import React, { useState } from 'react'
import { useNavigation } from '@react-navigation/native'
const MyProfile = () => {
const [phoneNumber, setPhoneNumber] = useState('');
<View style={styles.inputContainer}>
<View>
<Text style={styles.inputText}>Country</Text>
<TextInput
placeholder='#'
style={styles.countryCode}
/>
</View>
<View>
<Text style={styles.inputText}>Phone Number</Text>
<TextInput
placeholder='###-###-####'
value={phoneNumber}
setValue={setPhoneNumber}
style={styles.phoneNumber}
/>
</View>
</View>
const styles = StyleSheet.create({
inputContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
marginBottom: 30,
},
inputText: {
fontWeight: 'bold',
marginBottom: 10
},
countryCode: {
width: 60,
height: 40,
padding: 10,
backgroundColor: 'white',
borderRadius: 10
},
phoneNumber: {
width: 300,
height: 40,
padding: 10,
backgroundColor: 'white',
borderRadius: 10
},
如果需要更多資訊,我可以發布更多資訊。但這應該是與該特定輸入/螢屏相關的所有內容。謝謝
uj5u.com熱心網友回復:
發生這種情況,因為在您的 TextInput 組件中,您有“setValue”屬性,但它不存在,您必須執行以下操作:
<TextInput
placeholder='###-###-####'
value={phoneNumber}
onChangeText={(value) => setPhoneNumber(value)}
style={styles.phoneNumber}
/>
如果這解決了您的問題,我將不勝感激。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/525280.html
標籤:反应式输入文本
上一篇:如何使用axios獲取api?
