在侦听器内部使用await?

时间:2018-11-08 23:11:02

标签: javascript asynchronous

我实际上如何在这样的侦听器中使用await?我得到await is a reserved keyword

getPosts = async () => {
        return firebase.database().ref('posts/').orderByChild('created').on('value', snapshot => {
            let newPosts = []
            snapshot.forEach(post => {
                let location = await geofire.get(post.key)
                console.log("nice location", location)
                newPosts.push(post)
            })
            this.setState({ allPosts: newPosts }, () => console.log(this.state.allPosts))
        })
    }

0 个答案:

没有答案