am new in ReactJs ,I have try to get data in Array inside of object data. but am unable to get data object.I fetch successfully 'data' array but not able to get inside of 'item.name and description'. Please give the solution step by step.
JSON data
{
"lastUpdate":0,
"lanuage":"en",
"data":[
{
"itemId":"8f90647f-fafe-47a5-8204-8197e07432da",
"lastUpdate":1636440002,
"item":{
"name":"Hacivat Bundle",
"description":"",
"type":"bundle",
"rarity":"epic",
"series":null,
"cost":"???",
"upcoming":true,
"images":{
"icon":"https://dropin-bucket.mativecdn.com/cosmetics/br/8f90647f-fafe-47a5-8204-8197e07432da_kv88w8kp/icon.png",
"featured":null,
"background":"https://dropin-bucket.mativecdn.com/cosmetics/br/8f90647f-fafe-47a5-8204-8197e07432da_kv88w8kp/icon.png",
"information":"https://dropin-bucket.mativecdn.com/cosmetics/br/8f90647f-fafe-47a5-8204-8197e07432da_kv88w8kp/icon.png"
},
"backpack":{
},
"obtained":"",
"obtained_type":"none",
"ratings":{
"avgStars":3.49,
"totalPoints":192,
"numberVotes":55
},
"costmeticId":"8f90647f-fafe-47a5-8204-8197e07432da_kv88w8kp"
}
},
]
}
Source code
function Shop() {
useEffect(() => {
fetchitems();
}, []);
const [items, setItems] = useState([]);
const fetchitems = async () => {
const data = await fetch("https://fortnite-api.theapinetwork.com/upcoming/get"
);
const itemsdata = await data.json();
console.log(itemsdata.data);
setItems(itemsdata.data);
};
return (
<div>
{items.map(item => (
<h1>{item.name}</h1>
))}
</div>
);
}
export default Shop;