This is the issue I'm facing, it works fine outside componentDidMount and return the exact number when called in a function after render the views:
componentDidMount = () => {
var obj = snapshot.val()
var favoritesList = []
var keys = []
for(let a in obj){
favoritesList.push(obj[a])
keys.push(a)
}
this.setState({
favoritesList:favoritesList,
keys:keys,
})
console.log(this.state.keys.length)
console.log(this.state.favoritesList.length)
}
My goal is to show a text component when list is empty like so
if (this.state.favoritesList.length === 0)
this.setState({empty: true})
...
{this.state.empty ?
<Text>
Oh such empty!
</Text>
: null }
When calling this function it works, I am little bit confused:
test(item) {
console.log(item.index)
console.log(this.state.keys.length)
}