Error in IOS Chat with firebase in react native ([TypeError: _firebaseConfig.default.database is not a function. (In '_firebaseConfig.default')

Viewed 13

Hi All I configured all the necessary steps for firebase chat application . But i am facing issue with this.In recat native IOS . It's working on Android properly. I also Used react native firebase .But Getting this error. It is only in IOS ,In Android it's working fine .

[TypeError: _firebaseConfig.default.database is not a function. (In '_firebaseConfig.default.database()', '_firebaseConfig.default.database' is undefined)]


firebase.js 

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



const firebaseConfig = {
  apiKey: '',
  databaseURL: '',
  projectId: '',
  appId: '',
};

 if (!firebase.apps.length) {
    firebase.i`enter code here`nitializeApp(firebaseConfig);
 }
export default firebase;
</pre>



# Message.js #

import Firebase from './firebase-config';

export const sendMessage = async (from, to, message) => {
  try {
    return await Firebase.database()
      .ref('messages/' + from)
      .child(to)
      .push({
        from: from,
        to: to,
        message: message,
      });
  } catch (error) {
    console.log(error);
  }
};

export const receiveMessage = async (from, to, message) => {
  try {
    return await Firebase.database()
      .ref('messages/' + to)
      .child(from)
      .push({
        from: from,
        to: to,
        message: message,
      });
  } catch (error) {
    console.log(error);
  }
};

export const getMessages = async (from, to) => {
  try {
    await Firebase.database()
      .ref('messages')
      .child(from)
      .child(to)
      .on('value', dataSnapShot => {
        let message = [];
        dataSnapShot.forEach(data => {
          let jsonData = JSON.parse(JSON.stringify(data));

          message.push({
            from: jsonData.from,
            to: jsonData.to,
            message: jsonData.message,
          });
        });

        return message.reverse();
      });
  } catch (error) {
    console.log(error);
  }
};
0 Answers
Related