对象无效作为React子对象(找到的对象:带键的对象($$ typeof,type,key,ref,props,_owner,_store})

fig*_*ghg 6 firebase ecmascript-6 react-native react-native-android

我正在尝试在我的本机应用程序上使用firebase.但它给出了一个错误. 图像在这里

我的App.js代码如下

import React, { Component } from 'react';
import { Text } from 'react-native';
import firebase from 'firebase';

export default class HelloWorldApp extends Component {
  componentWillMount(){
    firebase.initializeApp({
      apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
      authDomain: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
      databaseURL: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
      projectId: 'xxxxxxxxxxxxxxxxxxxx',
      storageBucket: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
      messagingSenderId: 'xxxxxxxxxx'
    })
  }

  render() {
    return (
      <Text>Hello world!</Text>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

我能做什么?谢谢

Gro*_*Src 15

我今天遇到了这个问题.我在5.0.3和5.0.4之间的源代码上运行了差异,发现导出已经改变.我还发现,如果我将import语句更改为以下版本,它将与最新版本(5.3.0)一起使用:

import firebase from '@firebase/app'

如果你正在使用eslint,你可能会抱怨它应该列在项目依赖项中,但你可以忽略它.

您可能还想使用firebase的实际功能而不仅仅是核心导入.例如,要使用身份验证模块,您需要添加以下内容:

import '@firebase/auth'