I want retrieve all post then with each post there is a uid, using this uid i want to retrieve user information
My code is like this but it is not working and state is not changing in then block
getAllPost(){
let allPost = firebase.database().ref("all-post");
let postAll = [];
allPost.once("value").then(data => {
data.forEach(function (childSnapshot) {
let childData = childSnapshot.val();
childData.postId = childSnapshot.key;
let userInfo = firebase.database().ref(`users/${childData.uid}`);
userInfo.once("value").then(data => {
childData.userInfo = data;
postAll.push(childData);
})
})
}).then(()=>{
this.setState({ allPost: postAll,loading: false },);
}).catch(err => {
this.setState({ loading: false });
});
}