首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >React native -对象作为React子对象无效(已找到:具有键的对象{$$typeof,type,key,ref,props,_owner,_store})

React native -对象作为React子对象无效(已找到:具有键的对象{$$typeof,type,key,ref,props,_owner,_store})
EN

Stack Overflow用户
提问于 2018-05-28 02:32:06
回答 10查看 16.1K关注 0票数 29

我是React Native的新手,我收到了下面引用的错误:

对象作为React子对象无效(已找到:具有键{$$typeof,type,key,ref,props,_owner,_store}的对象)。如果您打算呈现一个子级集合,请改用数组。

以下是我在组件文件中包含的所有代码,除了样式:

代码语言:javascript
复制
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>
        );
    }
}

我很困惑如何解决这个问题。提前谢谢。

EN

回答 10

Stack Overflow用户

回答已采纳

发布于 2018-05-28 12:29:24

试试这个:

从App.js中删除firebase导入语句:

代码语言:javascript
复制
import firebase from 'firebase'

在Firebase初始化时,创建一个常量:

代码语言:javascript
复制
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();
...
}

对我来说,这个变通方法工作得很好!

票数 34
EN

Stack Overflow用户

发布于 2018-07-29 08:48:42

我今天遇到了这个问题。我对5.0.3和5.0.4之间的源代码进行了比较,发现导出发生了变化。我还发现,如果我将import语句更改为以下语句,则它可以与最新版本(5.3.0)一起工作:

代码语言:javascript
复制
import firebase from '@firebase/app'
import '@firebase/auth'

这样做可以避免在代码中间出现require,这是首选的imho。

票数 41
EN

Stack Overflow用户

发布于 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

票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50555275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档