我正在开发一个非常简单的提醒应用程序,作为使用 react 和 javascript 的介绍。(我是 javascript 的完整初学者,但对 ruby 等语言有经验。)我希望能够从这个 TextInput 组件(https://docs.expo.io/versions/v37.0.0/ react-native/textinput/#content)不使用类。我只想将输入存储为变量,并能够在我的代码中的其他任何地方调用它。第二个函数中的 {text} 变量是我要存储第一个函数的输入的地方。(为糟糕的英语道歉)我尝试运行它,它说它找不到变量“文本”,即使那是它被分配的内容。
function NewReminderScreen({ navigation }) {
const [value, onChangeText] = React.useState('click to add reminder.')
return (
<View style={styles.container}>
<TextInput
style={{height: 40, borderColor: 'white', borderWidth: 0, color:'#595959', fontSize:20, marginHorizontal:5}}
onChangeText={text => onChangeText(text)}
value = {value}
/>
);
}
function HomeScreen({ navigation }) {
return (
<View style={styles.container}>
<Text style={styles.buttontext}>{text}</Text>
<TouchableOpacity
onPress={() => navigation.navigate('NewReminderScreen')}
style={styles.plusbutton}>
<Text style={styles.buttontext}>+</Text>
</TouchableOpacity>
</View>
);
}