我正在尝试在我的反应原生项目中初始化firebase。
我正在初始化的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
答案 0 :(得分:8)
导出在5.0.4及更高版本中进行了更改。现在您需要这样做:
import firebase from '@firebase/app'
如果您使用的是eslint,则可能会抱怨它应该列在项目依赖项中,但是您可以忽略它。
您可能还希望使用firebase的实际功能,而不仅仅是核心导入。例如,要使用身份验证模块,您需要添加以下内容:
import '@firebase/auth'
答案 1 :(得分:0)
尝试初始化构造函数而不是componentWillMount
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 {
constructor(props){
super(props)
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;