I am a beginner in react-native and JS. Currently, I am working on a chat app project and attempting to implement a button that triggers the creation of a new chat using the provided function:
const createChat = async () =>{
await db
.collection("chats")
.add({
chatName: input,
})
.then(() => {
navigation.goBack();
})
.catch((error) => alert(error));
}
This is 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};