javascript - React native - 对象作为 React 子对象无效(发现:带有键 {$$typeof, type, key, ref, props, _owner, _store} 的对象)
问题描述
我是 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>
);
}
}
我很困惑如何解决这个问题。提前致谢。
解决方案
我今天遇到了这个问题。我对 5.0.3 和 5.0.4 之间的源代码进行了比较,发现导出发生了变化。我还发现,如果我将导入语句更改为以下内容,则它适用于最新版本(5.3.0):
import firebase from '@firebase/app'
import '@firebase/auth'
这样做可以让你避免require
在你的代码中间,这是首选恕我直言。
推荐阅读
- javascript - 在 Angular 8 for Safari 中,当路由到新组件时,由先前路由创建的布局没有被清除并且新路由没有加载
- swift - 如何解决 Swift 协议的规范问题
- javascript - 禁用 react-native 中的黄色警告消息
- python-3.x - 如何从给定的句子中提取更长的字符串并忽略子字符串?
- python - 一个python程序,它掷两个骰子并计算尝试次数,直到这些骰子的数量都是6
- python - 如何用 matplotlib 绘制一个 numpy 数组?
- ios - 我如何知道用户在商店中有应用内购买项目?
- ios - 为什么 Distriqt ANE for iOS 中的折扣促销优惠在生产模式下不起作用?
- python - 如何将 hdf 中的网格化卫星条带数据转换为 NASA GPM 卫星提供的 netcdf4?
- wso2 - WSO2APIM 网关副本同步延迟