I have an object like this:
myObject: {
"artists" : {
"items" : [ {
"id" : "423587fgerhk34t",
"images" : [ {
"height" : 640,
"url" : "https://url",
"width" : 640
}, {
"height" : 320,
"url" : "https://url",
"width" : 320
}],
"name" : "Artist Name",
} ]
}
}
Excuse me for sounding stupid, but how do I, in my React app, reach the ID, images and name? Can someone ELI5 this for me?
I've tried
Object.entries(myObject).map()
Object.keys(myObject).map()
myObject.artists.items.map()
but none of them works, at least not what I'm trying.
(I cannot change the object, it's a response from an API)
Really appreciate some help here. I need to render images and artistname and save the ID.
Edit, been trying this for example:
const displaySearchResult = Object.keys(myObject).map((artist) =>
<div className="search-result-item">
<img src={artist.images[1].url} alt="Artist"/>
<b key={artist.id}>{artist.name}</b>
</div>
)
But basically, all I'm getting is
"Objects are not valid as a React child (found: object with keys {href, items, limit, next, offset, previous, total}). If you meant to render a collection of children, use an array instead." (Objects.entries)
or
"Cannot read properties of undefined ('reading items')" (myObject.artists.items.map())