我的代码中是否有错误可以解释为什么可触摸不透明度似乎不起作用?



嗨👋,我目前正在关注一个购物清单应用程序项目/React Native 速成课程,我已经到了他的可触摸不透明度正在工作的地步,而我的不:(

我很好奇我是否犯了一个错误,或者我已经并排检查了我的代码与视频,但可能错过了一些东西。任何帮助将不胜感激!

import React, { useState } from 'react';
import { 
View,
Text, 
StyleSheet, 
TextInput, 
TouchableOpacity, 
} from 'react-native';
import Icon from 'react-native-vector-icons/dist/FontAwesome';
const AddItem = ({title,addItem}) => {
const [text, setText] = useState('');
const onChange = textValue => setText(textValue);
return (
<View>
<TextInput 
placeholder="Add item..." 
style={styles.input} 
onChangeText={onChange}
/>
<TouchableOpacity 
style={styles.btn} 
onPress={() =>
addItem(text)}>
<Text style={styles.btnText}>
<Icon name="plus" size=
{20} /> Add Item
</Text>
</TouchableOpacity>
</View>
);
};

const styles = StyleSheet.create({
input: {
height: 60,
padding: 8,
fontSize: 16,
},
btn: {
backgroundColor: '#c2bad8',
padding: 9,
margin: 5,
},
btnText: {
color: 'darkslateblue',
fontSize: 20,
textAlign: 'center',
},
});
export default AddItem;

在 Textinput 中,您不会通过函数调用传递文本

这样做

<TextInput 
placeholder="Add item..." 
style={styles.input} 
onChangeText={() => onChange(text)}
/>

相关内容

最新更新