【发布时间】:2019-10-23 01:01:49
【问题描述】:
我注意到当我尝试在文本输入字段中输入任何内容时,它会自动删除它。我已将问题范围缩小到值字段并将其注释掉允许我输入文本,但我不确定可能是什么问题。
import React, { useState } from 'react';
import { StyleSheet, Text, View, TextInput, Button } from 'react-native';
export default function App() {
const [enteredGoal, setEnteredGoal] = useState('');
const goalInputHandler = (enteredText) => {
setEnteredGoal(enteredGoal);
};
const addGoalHandler = () => {
console.log(enteredGoal);
};
return (
<View style={styles.screen}>
<View style={styles.inputContainer}>
<TextInput
placeholder="Course Goal"
style={styles.input}
onChangeText={goalInputHandler}
value={enteredGoal}
/>
<Button title='Add' onPress={addGoalHandler} />
</View>
<View />
</View>
);
}
【问题讨论】: