Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
Unhandled promise rejection: TypeError: _firebase.db.collection is not a function

I'm new to react-native and JS. My project is a chat app and I'm trying to create button that onPress creating new chat, using the following function:

const createChat = async () =>{
    await db
    .collection("chats")
    .add({
        chatName: input,
    })
    .then(() => {
        navigation.goBack();
    })
    .catch((error) => alert(error));

}

this my firebase.js file:


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


const firebaseConfig = {
    apiKey: "*",
    authDomain: "*",
    projectId: "*",
    storageBucket: "*",
    messagingSenderId: "*",
    appId: "*",
    measurementId: "*"
  };

  let app;

  if (firebase.apps.length === 0){
      app = firebase.initializeApp(firebaseConfig);
  } else {
        app = firebase.app();
  }

  const db = firebase.app();
  const auth = firebase.auth();

  export {db , auth};

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

const db = firebase.app(); // an instance of FirebaseApp

should be

const db = firebase.firestore(); // an instance of Firestore

Instead of learning using the compatibility library, consider learning the new Modular SDK instead as this will be the way forward.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!