I am having trouble returning an array of objects in desc order from firebase and javascript with react native. I am essentially "joining" two firebase parents and then pushing them into an array.
async loadChats(userId){
this.chatIdRef = firebase.database().ref("members");
this.chatIdRef.off();
this.chatsRef = firebase.database().ref("chats");
this.chatsRef.off();
items = [];
this.chatIdRef.child(userId).on('child_added', snap => {
this.chatsRef.child(snap.key).startAt().on('value', snapshot => {
items.push({
receiverId: snap.val().userId,
timeStamp: snapshot.val().createdAt,
name: snap.val().userName,
key: snapshot.key
});
this.setState({
dataSource: this.state.dataSource.cloneWithRows(items)
});
});
});
}
I have tried using "orderByChild('createdAt')" in my query but no luck.