0
I have the following code:
requireUsers = () => {
this.users = database.ref('users')
this.users.on('value', snapshot => {
this.state.users = snapshot.val()
Object.keys(snapshot.val()).map((value,key) => emails[key] = snapshot.val()[value].email)
})
}
requireSeries = () => {
Object.keys(emails).map((value,key) => emails[value] === email ? userId = Object.keys(this.state.users)[key] : "")
this.series = database.ref(`users/${userId}/series/${this.props.match.params.genre}`)
this.series.on('value', snapshot => {
this.setState({
series: snapshot.val()
})
})
}
componentDidMount = () => {
auth.onAuthStateChanged(user => {
if (user){
email = user.email
this.setState({
isLoggedIn: true,
isLoading: false
})
this.requireUsers()
window.setTimeout(this.requireSeries, 2000)
}
})
}
I know that function window.setTimeout(this.requireSeries, 2000)
will take some time, when the user registration number is large, but it is the only way I have found to load the data into the this.state.users
. I tried to use async
and await
but it didn’t work. Someone knows how to use it async
/ await
there?