[英]React-Native Passing users email and password to submit button
從“../MyModules/FirebaseAPI”導入 FirebaseAPI;
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
我的錯誤是 TypeError: undefined is not an object (評估'_FirebaseAPI.default.createUser')
我認為這是一個范圍界定問題,但不確定如何解決它。 仍然是新的反應。 任何幫助都是極好的!
submit
function 的email
和password
不是 scope。 您要么需要將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 (
....
)
或者
<TouchableOpacity
style={{marginTop: '5%'}}
onPress= {() => submit(email, password)}>
<View>
<Text>Submit</Text>
</View>
</TouchableOpacity>
此外,您將 FirebaseAPI 導入導入為
import * as FirebaseAPI from '../MyModules/FirebaseAPI';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.