[英]React-Native Passing users email and password to submit button
import FirebaseAPI from '../MyModules/FirebaseAPI';从“../MyModules/FirebaseAPI”导入 FirebaseAPI;
function submit() { function 提交(){
import FirebaseAPI from '../MyModules/FirebaseAPI'; export default function LinksScreen() { const [email, onChangeText] = React.useState('Enter Email'); const [password, onChangeText2] = React.useState('Enter Password'); const submit = () => { FirebaseAPI.createUser(email, password) } return ( <KeyboardAvoidingView style={styles.wrapper} behavior="padding"> <View style={styles.scrollViewWrapper}> <ScrollView style={styles.scrollView}> <Text style={styles.loginHeader}>Creat an Account </Text> <TextInput style={{ height: 40, borderColor: 'gray', borderWidth: 1 }} onChangeText={text => onChangeText(text)} value={email} /> <TextInput style={{ height: 40, borderColor: 'gray', borderWidth: 1 }} onChangeText={text => onChangeText2(text)} value={password} /> <TouchableOpacity style={{marginTop: '5%'}} onPress= {submit()}> <View> <Text>Submit</Text> </View> //code from FirebaseAPI.js import * as firebase from 'firebase' export const createUser = (email, password) => { firebase.auth().createUserWithEmailAndPassword(email, password).catch((error) => console.log('createUser error: ', error)); }
//etc //ETC
my error is TypeError: undefined is not an object (evaluating '_FirebaseAPI.default.createUser')我的错误是 TypeError: undefined is not an object (评估'_FirebaseAPI.default.createUser')
I assume its a scoping issue but unsure on how to fix it.我认为这是一个范围界定问题,但不确定如何解决它。 Still new at react.
仍然是新的反应。 Any help would be awesome!
任何帮助都是极好的!
The email
and password
are not scope of the submit
function. submit
function 的email
和password
不是 scope。 You either need to move the submit
function inside the component function or pass the values to the function您要么需要将
submit
function 移动到组件 function 内,要么将值传递给 function
export default function LinksScreen() {
const [email, onChangeText] = React.useState('Enter Email');
const [password, onChangeText2] = React.useState('Enter Password');
const submit = () => {
FirebaseAPI.createUser(email, password)
}
return (
....
)
OR或者
<TouchableOpacity
style={{marginTop: '5%'}}
onPress= {() => submit(email, password)}>
<View>
<Text>Submit</Text>
</View>
</TouchableOpacity>
Also where you are importing the FirebaseAPI import as此外,您将 FirebaseAPI 导入导入为
import * as FirebaseAPI from '../MyModules/FirebaseAPI';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.