-1

I have some objects in data.json file looking like this:

[{
    "id": "1",
    "srcImg": "https://upload.wikimedia.org/wikipedia/en/5/5a/Wearethechampions.jpg",
    "name": "We are the champions"
}]

All id inside of json are unique. There is my react code:

function MusicLi({ item }) { //we take item from map() in MusicList function 
  return (
    <div>
      <li key={item.id}>
        <img src={item.srcImg}/>
        <p>{item.name}</p>
      </li>
    </div>
  );
}

function MusicList() {
  return (
    <div>
      {data.map((item) => ( //data - imported json
        <MusicLi item={item}/> // send item object to MusicLi function
      ))}
    </div>
  );
}
  • still get an error – Alexander Turok Feb 15 '22 at 11:41