首页 > 解决方案 > 用firebase问题反应原生

问题描述

同样的代码正在使用 react js,但不适用于 react native,我不明白问题是什么?相同的代码也适用于 react native expo,但不适用于 react native cli

import React,{useState} from 'react'
import { View, Text, TextInput, Button } from 'react-native'
import { FirebaseApp } from './src/Services/FirebaseConfig';

import * as firebase from 'firebase';
import '@firebase/firestore'



var firebaseConfig = {
  apiKey: "AIzaSyD7KpH12s63Pa_ibUFv0V_NU_JIDByRJtk",
  authDomain: "hrinstallmentscli.firebaseapp.com",
  databaseURL: "https://hrinstallmentscli.firebaseio.com",
  projectId: "hrinstallmentscli",
  storageBucket: "hrinstallmentscli.appspot.com",
  messagingSenderId: "587843211028",
  appId: "1:587843211028:web:e6a71a1592f7aaa42d7c01",
  measurementId: "G-XQW1WDCJ8C"
};
// Initialize Firebase
var FirebaseApp = firebase.initializeApp(firebaseConfig);
const App = () => {
const fetchBlogs = () => {
    console.log('clicked')
    FirebaseApp.firestore().collection("checking").add({
        firstName: 'check',
        lastName: 'check last'
    })
    .then(function() {
        console.log("Document successfully written!");
    })
    .catch(function(error) {
        console.error("Error writing document: ", error);
    });

  }
 return (
    <View>
      <Text>Checking!!!</Text>
      <View>
        <TextInput placeholder="first name" onChangeText={ (value) => _OnChangeFirstName(value)} />
      </View>
      <View>
        <TextInput placeholder="last name" onChangeText={(value) => _OnChangeLastName(value)} />
      </View>
      <View>
        <Button title="Submit" onPress={() => fetchBlogs()} />
      </View>
    </View>
  )


}

我已经在 web 上尝试过它并 react native expo 它在任何地方都可以使用,但不能与 react native cli 一起使用...依赖项是

“依赖”:{“firebase”:“^7.14.3”,“react”:“16.11.0”,“react-native”:“0.62.2”}

我不想使用 react native firebase 包,我觉得它已经过时并且我必须降级 react native 版本等。

标签: reactjsfirebasereact-native

解决方案


推荐阅读