reactjs - 用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 版本等。
解决方案
推荐阅读
- c++ - 是否可以在 C++ 中调用没有直接引用的函数?
- security - Liberty 服务器:isUserInRole 始终返回 false
- collision-detection - 如何检测 Godot 中的碰撞?
- spring-boot - 创建 Spring Boot 项目和 Maven
- php - 使用 XDebug 进行调试时,如何定义 PHP 对象在 VSCode 中的显示方式?
- python - 'numpy.float64' 类型的对象没有 len():我该如何解决这个问题?
- oculus - 如何在 Oculus Quest 浏览器中自动打开链接?
- r - 以向量化方式基于数据子集定义多行
- firebase - 从子集合 firestore + FLUTTER 中检索信息
- php - Laravel 关系不适用于 leftJoin