How to import Firebase Firestore into a create-react-app project using ES6 syntax

后端 未结 5 1290
余生分开走
余生分开走 2021-01-13 11:20

I\'m having trouble getting Firebase Firestore to work with the basic create-react-app boilerplate. Does anyone have a working sample?

The Get Started doc only expla

5条回答
  •  囚心锁ツ
    2021-01-13 11:38

    I created a config file for firebase:

    import * as firebase from 'firebase';
    
    const config = { /* COPY THE ACTUAL CONFIG FROM FIREBASE CONSOLE */
        apiKey: "apiKey",
        authDomain: "domen.firebaseapp.com",
        databaseURL: "https://domen.firebaseio.com",
        projectId: "lavs-mercury",
        storageBucket: "",
        messagingSenderId: "id"
    };
    
    export default firebase.initializeApp(config);
    

    Then I just import this module to file where I want to use. For example:

    import * as actionTypes from './actionTypes';
    import firebase from "../../firebase-module";
    
    export const logout = () => {
        firebase.auth().signOut();
        return {
            type: actionTypes.LOGOUT
        }
    };
    

提交回复
热议问题