0

When I run this code (react native), the following error appears:

FirebaseError: Firebase: firebase.database() takes either no argument or a Firebase App instance. (app/invalid-app-argument).

Here's the code (when I run the similar code in other files(inside the same project) works perfectly):

import React from "react";
import { View, Text } from "react-native";
import * as firebase from "firebase";

class screen extends React.Component {

  componentDidMount() {
    firebase.auth().onAuthStateChanged((user) => {
      if (user) {
        firebase
          .database()
          .ref("users/" + user.uid + "/keys")
          .on("value", function (snapshot) {
            console.log(snapshot.val()); //works
            snapshot.forEach(function (childSnapshot) {
              console.log("hello"); //works
              var key = childSnapshot.val();
              firebase
                .database("users/" + key + "/whatever")
                .on("value", function (snapshot) {
                  console.log(snapshot.val()); //Doesn't work
                });
            });
          });
      }
    })
  }

  render() {
    return (
      <View>
       <Text>Hello</Text>
      </View>
    );
  }
}

export default screen;
3
  • 1
    Are you sure that the error message refers to this code? If so, how did you make that connection? Commented Aug 24, 2020 at 19:37
  • 1
    It seems likely that you didn't properly initialize Firebase. Assuming react-native-firebase, then you need to set up your config as explained here and should be importing @react-native-firebase/database rather than the raw Firebase SDK. If you are not using a third party lib, then the code you shared here can't produce the error described. Commented Aug 24, 2020 at 19:41
  • This is react native and this is not how you use firebase with react-native. follow the guide Commented Aug 24, 2020 at 19:56

1 Answer 1

1

Ok i figured it out. I had to write the reference of the database inside "ref()" not inside "database()"... silly error haha

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.