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>
        );
    }
}

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

原文由 scrazz 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 665
2 个回答

尝试这个:

从 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();
...
}

对我来说,这种解决方法非常有效!

原文由 Clebertom 发布,翻译遵循 CC BY-SA 4.0 许可协议

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

 import firebase from '@firebase/app'
import '@firebase/auth'

这样做可以让您避免代码中间的 require ,恕我直言,这是首选。

原文由 groksrc 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题