Skip to content Skip to sidebar Skip to footer

React Native Firebase Datasnapshot

I'm trying to implement firebase into my React Native app with the following code: import * as firebase from 'firebase' var fireBaseconfig = { apiKey: 'MY KEY', authDomain: 'MY DOM

Solution 1:

In firebase.database().ref, ref is a function so should be ref().

Since that returns a Reference, you have to call child() to get a child.

So:

import * as firebase from'firebase'var fireBaseconfig = {
apiKey: "MY KEY",
authDomain: "MY DOMAIN",
databaseURL: "MY URL",
storageBucket: "MY BUCKET",
};
var firebaseApp = firebase.initializeApp(fireBaseconfig);
var rootRef = firebase.database().ref();
var ref = rootRef.child("items");
ref.once("value").then(function(snapshot) {
   snapshot.forEach(function(childSnapshot) {
     var key = childSnapshot.key;
     var childData = childSnapshot.val();
   });
});

I also renamed the query variable, because it's actually not a query but just another reference to a child location.

Post a Comment for "React Native Firebase Datasnapshot"