【发布时间】:2021-01-15 22:05:43
【问题描述】:
我有自定义 TextInput 组件的代码,我想将此组件用于登录屏幕的用户名和密码值,但是,我不知道如何检索特定实例的文本输入值.
import React from 'react';
import { TextInput, StyleSheet, View, ImagePropTypes } from 'react-native';
const TextInputCustom = (props) => {
const [value, onChangeText] = React.useState();
return (
<View style={styles.container}>
<TextInput
placeholder={props.name}
style={styles.textInput}
onChangeText={text => onChangeText(text)}
value={value}
/>
</View>
);
}
导入后我在登录屏幕中创建
<TextInputCustom name="Username"/>
<TextInputCustom name="Password"/>
如何获取该值以便可以将其分配给每个 TextInputCustom 实例的变量?
【问题讨论】:
-
您是否有权访问该组件的 API?那将是一个开始寻找的好地方。通常,您有
onChange处理程序。我还看到你有onChangeText作为道具,但由于你仍然面临问题,我假设它不起作用。所以尝试检查 API 并使用正确的道具 -
你试过使用回调函数吗?
标签: javascript reactjs react-native