Reputation: 73
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;
Upvotes: 0
Views: 541
Reputation: 73
Ok i figured it out. I had to write the reference of the database inside "ref()" not inside "database()"... silly error haha
Upvotes: 1