我是React Native的新手,我收到了下面引用的错误:
对象作为React子对象无效(已找到:具有键{$$typeof,type,key,ref,props,_owner,_store}的对象)。如果您打算呈现一个子级集合,请改用数组。
以下是我在组件文件中包含的所有代码,除了样式:
import React, { Component } from 'react';
import { View, Text, TextInput, TouchableOpacity, Image, StyleSheet } from 'react-native';
import firebase from 'firebase';
class LoginForm extends Component {
state = { email: '', password: '', error: '', loading: false };
onButtonPress(){
const email = this.state.email;
const password = this.state.password;
this.setState({error: '', loading: true});
firebase.auth().signInWithEmailAndPassword(email, password)
.then(this.onLoginSuccess.bind(this))
.catch(() => {
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(this.onLoginSuccess.bind(this))
.catch(this.onLoginFail.bind(this));
});
}
onLoginSuccess(){
this.setState({email: '', password: '', error: '', loading: false});
}
onLoginFail(){
this.setState({error: 'Nie udalo sie utworzyc konta.', loading: false});
}
render(){
return(
<View style={styles.container}>
<View style={styles.imageContainer}>
<Image
style={styles.image}
source={require('../images/loginIcon.png')}
/>
</View>
<View style={styles.formContainer}>
<TextInput
style={styles.input}
placeholder="Email..."
placeholderTextColor='rgba(255,255,255,0.9)'
underlineColorAndroid='rgba(0,0,0,0)'
onChangeText={(email) => this.setState({email: email})}
value={this.state.email}
autoCorrect={false}
/>
<TextInput
style={styles.input}
placeholder="Hasło..."
placeholderTextColor='rgba(255,255,255,0.9)'
underlineColorAndroid='rgba(0,0,0,0)'
autoCorrect={false}
onChangeText={(password) => this.setState({password: password})}
value={this.state.password}
secureTextEntry
/>
<TouchableOpacity style={styles.buttonContainer}>
<Text style={styles.button}>
Zaloguj się
</Text>
</TouchableOpacity>
<Text style={styles.error}>
{this.state.error}
</Text>
</View>
</View>
);
}
}
我很困惑如何解决这个问题。提前谢谢。
发布于 2018-05-28 12:29:24
试试这个:
从App.js中删除firebase导入语句:
import firebase from 'firebase'
在Firebase初始化时,创建一个常量:
initializeFirebase() {
const firebase = require("firebase");
// Initialize Firebase
var config = {
...
};
firebase.initializeApp(config);
//inicializando o firestore
const firestore = require("firebase/firestore");
db = firebase.firestore();
db.settings({ timestampsInSnapshots: true });
}
componentWillMount() {
this.initializeFirebase();
...
}
对我来说,这个变通方法工作得很好!
发布于 2018-07-29 08:48:42
我今天遇到了这个问题。我对5.0.3和5.0.4之间的源代码进行了比较,发现导出发生了变化。我还发现,如果我将import语句更改为以下语句,则它可以与最新版本(5.3.0)一起工作:
import firebase from '@firebase/app'
import '@firebase/auth'
这样做可以避免在代码中间出现require
,这是首选的imho。
发布于 2018-07-13 04:27:18
这是firebase版本5.0.6的一个问题,而降级到某个版本将解决此issue.for示例尝试以下命令
$ npm install --save firebase@5.0.4
如果版本5.0.4也不适用于您,请尝试版本4.9.1,因为这是我正在使用的版本,它为我解决了这个问题
$npm install --save firebase@4.9.1
https://stackoverflow.com/questions/50555275
复制相似问题