Javascript React native-对象作为React子对象无效(找到:具有键{$$typeof,type,key,ref,props,_owner,_store}的对象)
我对React Native不熟悉,下面引用了一个错误: 对象作为React子对象无效(找到:具有键{$$typeof,type,key,ref,props,_owner,_store}的对象)。如果要呈现子对象集合,请改用数组 以下是我在组件文件中包含的全部代码,除了样式:Javascript React native-对象作为React子对象无效(找到:具有键{$$typeof,type,key,ref,props,_owner,_store}的对象),javascript,android,reactjs,react-native,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 }
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>
);
}
}
import React,{Component}来自'React';
从“react native”导入{View,Text,TextInput,TouchableOpacity,Image,StyleSheet};
从“firebase”导入firebase;
类LoginForm扩展组件{
状态={电子邮件:“”,密码:“”,错误:“”,加载:false};
onButtonPress(){
const email=this.state.email;
const password=this.state.password;
this.setState({错误:“”,正在加载:true});
firebase.auth().signiWithEmailandPassword(电子邮件,密码)
.then(this.onloginsucess.bind(this))
.catch(()=>{
firebase.auth().createUserWithEmailAndPassword(电子邮件,密码)
.then(this.onloginsucess.bind(this))
.catch(this.onLoginFail.bind(this));
});
}
onloginsucess(){
this.setState({电子邮件:“”,密码:“”,错误:“”,加载:false});
}
onLoginFail(){
this.setState({error:'Nie udalo sie utworzyc konta',load:false});
}
render(){
返回(
this.setState({email:email})}
值={this.state.email}
自动更正={false}
/>
this.setState({password:password})}
值={this.state.password}
secureTextEntry
/>
扎洛古吉·西ę
{this.state.error}
);
}
}
我很困惑如何解决这个问题。提前感谢。试试这个:
从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();
...
}
对我来说,这个解决方法非常有效 firebase 5.0.6版存在此问题,而降级到某个版本将解决此问题。例如,请尝试以下方法
$npm安装--保存firebase@5.0.4
如果版本5.0.4也不适用于您,请尝试版本4.9.1,因为这是我正在使用的,它为我解决了这个问题
$npm安装--保存firebase@4.9.1
我今天遇到了这个问题。我对5.0.3和5.0.4之间的源代码进行了比较,发现导出已经更改。我还发现,如果我将import语句更改为以下内容,则该语句适用于最新版本(5.3.0):
这样做将允许您在代码中间避免<代码>要求,这是首选的IMHO。 我也遇到了同样的问题,我通过删除firebase的导入语句解决了这个问题:
import firebase from 'firebase'
并通过在我的组件内创建一个全局常量来替换它,该常量将在组件完成安装后初始化:
componentDidMount() {
this.firebase = require('firebase');
}
然后您可以使用this.firebase
使用所有firebase方法。。。
例如:
this.firebase.auth().onAuthStateChanged((user) => {
//Some Code
});
这对我有用
$npm install --save firebase@4.9.1
在firebase文档中,他们说:
修复了ES6通配符导入破坏闭包编译器的问题
LINK>此版本随firebase 5.0.6版而来。通过运行此命令,尝试降级firebase版本
$ npm install --save firebase@5.0.4
在此之后,如果问题仍然存在,请尝试将firebase插件降级至4.9.1版
$npm install --save firebase@4.9.1
尝试将导入语句更改为:
import firebase from '@firebase/app';
},,
有了以上的依赖关系,我通过以下方法解决了这个问题
import firebase from '@firebase/app';
回滚到firebase 5.0.3版也解决了这个问题。我没有降级,只是添加了
import "@firebase/database";
这意味着你要导入你想使用的每个firebase组件…(希望这是正确的)
但是它对我来说非常有效请更具体一些。你能试着把你的代码大小减少到一个最小的例子吗?我分析了这个代码好几个小时,我真的不知道问题出在哪里。如果我删除除render()之外的所有方法,问题就不会出现。我也无法直接看到问题,但我认为它一定与其中一个标记有关。你能试着对组件及其子组件进行注释,看看你是否仍然收到错误?@dentemm我删除了内部的这两个标记,没有任何影响。你也尝试了错误消息的标记吗?非常感谢你的帮助,它可以工作!事实上,从App.js中删除firebase导入语句并不奏效,但当我从我的组件(LoginForm.js)中删除此导入并在onButtonPress()方法中创建此firebase变量时,它最终启动了。谢谢@ClebertomThis为我工作,但不要错过下面@GrokSrc的解决方案,它解释了如何仍然使用import
->import firebase from'@firebase/app'
和import'@firebase/auth'
@Celebertom,我如何在我的config.js文件中使用此解决方案,它只是js文件而不是react组件?Config.js没有react设置,因此,如何使用componentWillMount()?林克:这对我有用。我开始使用版本4.9.1,但问题消失了。此方法给我错误:“\u firebase.default.database不是函数:(在“\u firebase.default.database()”中,“\u firebase.default.database”未定义)”。好的,我修好了。我将作为一个单独的评论发布。为了让它起作用,你需要导入你正在使用的Firebase的所有部件。我没有使用Auth,而是使用存储和数据库。所以我不得不补充一句
import firebase from '@firebase/app';
import "@firebase/database";