首页 / REACT / javascript – React native – 对象无效作为React子对象(找到:具有键{$$typeof,type,key,ref,props,_owner,_store}的对象)
javascript – React native – 对象无效作为React子对象(找到:具有键{$$typeof,type,key,ref,props,_owner,_store}的对象)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – React native – 对象无效作为React子对象(找到:具有键{$$typeof,type,key,ref,props,_owner,_store}的对象),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2479字,纯文字阅读大概需要4分钟。
内容图文
我是React Native的新手,我在下面引用了一个错误:
Objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props, _owner, _store}). If you meant to render a collection of children, use an array instead.
这是我的整个代码包含在组件文件中,除了样式:
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>
);
}
}
我很困惑如何解决这个问题.提前致谢.
解决方法:
尝试这个:
从App.js中删除firebase import语句:
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();
...
}
对我来说,这个解决方案非常有效!
内容总结
以上是互联网集市为您收集整理的javascript – React native – 对象无效作为React子对象(找到:具有键{$$typeof,type,key,ref,props,_owner,_store}的对象)全部内容,希望文章能够帮你解决javascript – React native – 对象无效作为React子对象(找到:具有键{$$typeof,type,key,ref,props,_owner,_store}的对象)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。