Assume that the data look like this
post: {
authorId: '123AA',
title: 'first Post',
body: 'yay'
}
author: {
uid: '123AA',
displayName: 'Richard'
email: 'im@richard.com'
}
I want to render a post with the author's name:
<div className="post">
<div className="title">{post.title}</div>
<div className="body">{post.body}</div>
<div className="author-name">{post.author.displayName}</div> //problem
</div>
A fetched post item only contains an author's uid
, but I need the author's displayName
. How do I populate the author field when retrieving the posts? This is what I do to fetch the posts right now:
const postsRef = firebase.database().ref('posts/')
postsRef.on('value', (snapshot) => {
this.setState({posts: snapshot.val()})
})