[英]How to get value of child component TextInput of NavigatorIOS in react-native
[英]How to get the TextInput value in react-native
我有这个代码,我在那里得到用户输入。 但是当我在控制台记录它以检查它时,我得到了一个object of type undefined
的object of type undefined
。 我在这里提供我的代码。 请更正我的代码,以便修复此错误。
export default function App() { const [enteredGoal, setGoal] = useState(''); const goalInputHandler = (enteredText) => { setGoal(enteredText); }; const addGoalHandler = () => { console.log(enteredGoal); } return ( <View style={styles.screen}> <StatusBar style="auto" /> <View style={styles.inputTextContainer}> <TextInput style={styles.TextInput} placeholder="Course Goal" onChange={goalInputHandler} value={enteredGoal} /> <Button title="ADD" onPress={addGoalHandler} /> </View> </View> ); }
你必须使用 onChangeText 道具
onChangeText={(text)=>goalInputHandler(text)}
这会将当前文本传递给goalInputHandler 函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.