reactjs - 对象作为 react 子无效(react-native)

标签 reactjs firebase react-native firebase-authentication

我正在尝试在我的 react native 项目中初始化 firebase。

This is the error I am facing
App.js 的代码我在哪里初始化它

import React, {Component} from 'react';
import {View, Text} from 'react-native';
import {Provider} from 'react-redux';
import {createStore} from 'redux';
import reducers from './reducers';
import firebase from 'firebase';

class App extends Component {

  componentWillMount () {
    const config = {
      apiKey: "",
      authDomain: "",
      databaseURL: "",
      projectId: "",
      storageBucket: "",
      messagingSenderId: ""
    };
    firebase.initializeApp(config);
  }

  render() {
    return (
      <Provider store={createStore(reducers)}>
      <View>
        <Text>Hello! </Text>
      </View>
    </Provider>
    );
  }
}

export default App;

当我只包含 import firebase from 'firebase'; 时,我什至面临同样的错误并且不要初始化 config

最佳答案

导出在 5.0.4 及更高版本中发生了变化。现在你需要这样做:
import firebase from '@firebase/app'
如果你正在使用 eslint,你可能会提示它应该列在项目依赖项中,但你可以忽略它。

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

关于reactjs - 对象作为 react 子无效(react-native),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50730706/

相关文章:

react-native - 如何在 React Native 中找到组件的 x,y 位置

ios - 开发一个 ARKit 应用程序,留下文本供其他人查看

javascript - 在构造函数之外实例化的 ES6+ 实例属性

javascript - 在 react 中设置按钮动画

javascript - 如何测试调度自定义事件的方法

android - 从简单的 FireBase 数据库中读取

android - 查询 2 个 GeoPoints 之间的位置

ios - 如何创建 Objective-C 桥接头文件?

ios - 在 react native 应用程序中使用提取时出错

javascript - ReactJS 表单渲染问题