Firestore React error on

Asked

Viewed 50 times

0

I’m trying to get the information from my collection in firebase but am getting the following error:

Typeerror: Undefined is not an Object (evaluating '_firebaseConnection.default.db.Collection')

this is my firebase code

import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
import 'firebase/database';

let firebaseConfig = {
  apiKey: "",
  authDomain: "",
  databaseURL: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: "",
  measurementId: ""

};

if (!firebase.apps.length) {
  firebase.initializeApp(firebaseConfig)
}

const db = firebase.firestore();



export {db}

export default firebase;

the firestore only appears when I put:

 const db = firebase.firestore();
  export default {
      firebase,
     db
 };

from this above format I cannot exit the auth error application

Code from my book screen where the error occurs:

   import React, { useEffect, useState } from "react";

import {
    StatusBar,
    FlatList, View
} from "react-native";
import * as OpenAnything from "react-native-openanything";

import {
    Container,
    InpuText,
    ViewFlatlist,
    Image,
    TextOne,
    ButtomSimple,
    TextButtom,
    ContainerRow,
    ContainerInput,
} from "./styles";
import { Card } from "react-native-elements";
import firebase from '../../services/firebaseConnection';

export default function Libery() {
    const [Libery, setLibery] = useState([]);


    useEffect(() => {
        firebase.db.collection("biblioteca").onSnapshot((querySnapshot) => {
            const Libery = [];
            querySnapshot.docs.forEach((doc) => {
                const { title, category, uri, pdf } = doc.data();
                Libery.push({
                    id: doc.id,
                    title,
                    category,
                    uri,
                    pdf
                });
            });
            console.log(Libery)
            setLibery(Libery);
        });
    }, []);
  • How’s the import in the component?

  • import React, { useEffect, useState } from "react"; import { StatusBar, FlatList, View } from "react-native"; import * as OpenAnything from "react-native-openanything"; import { Container, InpuText, ViewFlatlist, Image, TextOne, ButtomSimple, TextButtom, ContainerRow, ContainerInput, } from "./styles"; import { Card } from "react-native-elements"; import firebase from '../../services/firebaseConnection'; export default function Libery() { const [Libery, setLibery] = useState([]);

1 answer

0

Solved.

I just needed to call the Firestone in to book screens

Thus:

import 'firebase/firestore';

const db = firebase.firestore();

db.Collection("library").....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.