[英]I am getting an error when i was making a new react - native app
Uncaught TypeError: firebase_compat_app__WEBPACK_IMPORTED_MODULE_4__.initializeApp is not a function未捕获的类型错误:firebase_compat_app__WEBPACK_IMPORTED_MODULE_4__.initializeApp 不是 function
This is a error which is coming when I am making a new react - native app这是我做出新反应时出现的错误 - 本机应用程序
CODE:代码:
import { ActivityIndicator, StyleSheet, View } from 'react-native'
import React from 'react';
import * as firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/database';
class LoadingScreen extends React.Component {
componentDidMount() {
this.checkIfLoggedIn();
};
checkIfLoggedIn = () => {
firebase.auth().onAuthStateChanged(user => {
if (user) {
this.props.navigation.navigate('DashboardScreen')
} else {
this.props.navigation.navigate('LoginScreen')
};
});
};
render() {
return (
<View style={styles.container}>
<ActivityIndicator size="large" />
</View>
)
}
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}
});
export default LoadingScreen;
I see a few concerns/problems with the above code:我看到上述代码存在一些问题/问题:
compat
is not encouraged;compat
; Firebase explicitly stated that this is a stop-gap measure for people with large v8 code bases that need to move to v9 but want to stick with the v8 syntax -- and that the v8 syntax (and compat
) are to be deprecated in the very near future compat
)将在非常时期被弃用不远的将来onAuthStateChanged()
listener;onAuthStateChanged()
侦听器; this is a resource leak in your codefirebase.auth()
without specifying the particular app
) -- without knowing how you initialized Firebase we can't tell if that is "doing the right thing"firebase.auth()
而没有指定特定的app
) - 不知道您如何初始化 Firebase 我们无法判断这是否是“做正确的事”BTW: I have moved to using the Context API for initializing Firebase and sharing its services to the rest of my app.顺便说一句:我已经开始使用上下文 API 来初始化 Firebase 并将其服务共享给我的应用程序的 rest。 You can see this pattern in the FirebaseProvider.js of the following starter project.
您可以在以下启动项目的 FirebaseProvider.js 中看到此模式。 Feel free to use/copy as you see fit: https://github.com/gregfenton/react-and-user-profiles-with-firebase-auth-and-firestore
随意使用/复制您认为合适的: https://github.com/gregfenton/react-and-user-profiles-with-firebase-auth-and-firestore
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.