scr*_*azz 26 javascript android reactjs react-native
我是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>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我很困惑如何解决这个问题.提前致谢.
Gro*_*Src 41
我今天遇到了这个问题.我在5.0.3和5.0.4之间的源代码上运行了差异,发现导出已经改变.我还发现,如果我将import语句更改为以下版本,它将与最新版本(5.3.0)一起使用:
import firebase from '@firebase/app'
import '@firebase/auth'
Run Code Online (Sandbox Code Playgroud)
这样做可以让你避免require代码中间,这是首选的imho.
小智 33
试试这个:
从App.js中删除firebase import语句:
import firebase from 'firebase'
Run Code Online (Sandbox Code Playgroud)
在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();
...
}
Run Code Online (Sandbox Code Playgroud)
对我来说,这个解决方案非常有效!
小智 15
这是firebase版本5.0.6的问题,而降级到版本将解决此问题.例如试试这个
$ npm install --save firebase@5.0.4
如果版本5.0.4也不适用于您而不是尝试版本4.9.1,因为这是我正在使用的,它为我解决了这个问题
$npm install --save firebase@4.9.1
| 归档时间: |
|
| 查看次数: |
14351 次 |
| 最近记录: |