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 this window.setTimeout(this.requireSeries, 2000)
function will take some time, when the user registration number is large, but it is the only way I found to load the data in this.state.users
. I tried to use async
and await
but it did not work. Does anyone know how you would use async
/ await
there?