so I'm rendering out an array of posts. Each post has a unique user id associated with it, which I'm trying to use in another API call to return the user's image for that post.
Currently i have it setup like so
Rendering out the post
{data?.map((data) => (
<div className="allpostsingle" key={data.id} onClick={() => sendTo(data.id)}>
<div className="allpostheader">
<img src={getUrl(data.user)}/>
<p>{data?.description}</p>
</div>
</div>
))}
The function to get the image URL
const getUrl = async (id) => {
let url = `http://127.0.0.1:8000/api/user/${id}/`
const response = await fetch(url)
const data = await response.json()
const avatarurl = data.avatar
return avatarurl
}
The issue with this is it returns a promise instead of the URL. I know you can set it in a state to get the url, but then it wouldnt be unique to each post?
Im just wondering how i can solve this or if theres a different way to solve this issue.