I am trying to get the return value of fetch call and pass it as a prop to another react component. The issue i am having is the function returns as undefined.
render() {
function getUserWhoPosted (id){
let url = new URL('http://10.6.254.22:5000/userinformation' + '/'+ id)
fetch(url).then((resp) => resp.json()) // Transform the data into json
.then((data) => {
  console.log(data[0].firstName)
  return data[0].firstName
})
}
//  console.log(getUserWhoPosted(1))
const reversedProps = this.props.posts.reverse();
const postItems = reversedProps.map(post => (
  // console.log(getUserWhoPosted(post.userId)),
  <PostBodyTemplate key={post.id} title={post.title} postBody={post.postBody} giphyUrl = 
  {post.giphyUrl} userWhoPosted = { getUserWhoPosted(post.userId) }/>
  ));
 return (
  <div>
     <h1>{postItems}</h1> 
  </div>
 )
 }
getUserWhoPosted(post.userId) should return a name, it returns as undefined.
 
    