I know it's a pretty simple question but I don't know why not work with me!
I'm declaring an array and after getting the data from the server I pushed them into these empty array and when I log them I can see my data like this
I'm using Loadash to get the unique obj so why not work for me?
here's my function
_uniqUser= () => {
let currentUser = firebase.auth().currentUser.uid;
let ref = firebase.database().ref(`users/${currentUser}`);
let providersKeys = [];
ref.once("value").then(snapshot => {
snapshot.forEach(childsnap => {
providersKeys.push(childsnap.key);
});
let providers = [];
providersKeys.forEach(key => {
firebase
.database()
.ref("providers")
.child(key)
.once("value")
.then(providersShot => {
let username = providersShot.val().username;
providers.push({ username: username, key: key });
});
});
let uniq = _.uniqBy(providers,"key")
console.log(uniq); // I got Empty array
console.log(typeof providers); // I got Object!!
this.setState({ providers:uniq, noChat: false });
// this.setState({ providers, noChat: false },()=>console.log(this.state.providers)) // I see the above image!
});
};