简体   繁体   English

将 firebase 导入 react-native

[英]importing firebase to react-native

I'm trying to use the firebase in a react native project我正在尝试在本机项目中使用 firebase

I installed the firebase in my project:我在我的项目中安装了 firebase:

npm install --save firebase

and I'm importing it into my app.js我将它导入我的 app.js

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

type Props = {};
export default class App extends Component<Props> {

  render() {
    return (
      <View >
        <Text>Testando Firebase</Text>    
      </View>
    );
  }
}

and then the error is displayed:然后显示错误:

Objects are not valida as a react child (found: object with keys{&&typeof, type, key, ref, props, _owner, _store}).对象不能作为反应子对象进行验证(发现:对象带有键{&&typeof, type, key, ref, props, _owner, _store})。 If you meant to render a collection of children, use an array instead.如果您打算渲染一组子项,请改用数组。

but when I remove the import from firebase, the app works perfectly.但是当我从 firebase 中删除导入时,该应用程序运行良好。

Try to install the version 5.0.2.尝试安装 5.0.2 版本。 Use this command as administrator:以管理员身份使用此命令:

npm uninstall firebase    
npm install --save firebase@5.0.2

As far as i see, the current version (5.0.4) is buggy!据我所知,当前版本(5.0.4)有问题!

You need to import as follow您需要按如下方式导入

import * as firebase from 'firebase';从'firebase'导入*作为firebase;

You first must have firebase installed.您首先必须安装 firebase。

The solution gentlemen is to uninstall the current version of firebase and install an older version.解决方案先生们是卸载当前版本的 firebase 并安装旧版本。 1st step npm uninstall firebase第一步 npm 卸载 firebase

2nd step npm i firebase@8.0.3第二步 npm i firebase@8.0.3

It was the version that worked for my case, good luck that force is with you!这是适用于我的案例的版本,祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM