I'm learning react native, and now i'm using firebase...
But i am not able to get data from firebase database as easily as java, i am wondering if i am doing something wrong somewhere, someone please help me, thanks!
It can't get the data to the setCarts...
Here is my code and firebase database!
const getCartProducts = () => {
database()
.ref("carts/" + user.uid + "/")
.on("value", function (snapshot) {
let array = [];
snapshot.forEach(function (childSnapshot) {
let childData = childSnapshot.val();
let k = childSnapshot.key;
database()
.ref("products/" + k)
.on("value", function (s) {
let sData = s.val();
array.push({
id: k,
count: childData.count,
imageUrl: sData.imageUrl,
name: sData.name,
type: sData.type,
price: sData.price,
like: sData.like,
popular: sData.popular,
storageQuantity: sData.storageQuantity,
description: sData.description,
});
});
});
// console.log(array);
setCarts(array);
});
};